Python Numpy squeeze()

Python Numpy squeeze()

NumPy generally stands for Numerical Python and it is a general purpose array processing always provides a high performance multidimensional array object. Numpy is usually for creating an array of n dimensions.

Method Name :numpy.squeeze(arr, axis)
Description :The function is used to remove single-dimensional entries from the shape of an array. By this method, we are able to squeeze the size of a matrix by using the same method. But we should know one thing that we use this method on the Nx1 size of the matrix which results out as a 1xN matrix.

In this article, I will tell you about the parameter and its description
Parameter Name: arr
Description: input data in the form of an array

Parameter Name: axis
Description : int or tuple of int
The parameter selects a subset of the single-dimensional entries in the shape. If an axis is being selected with a shape entry greater than one, an error is being raised.

Return : The input array, but with a subset of the dimensions of length 1 removed. This is always itself or a view into array.

The first step would be to give syntax
numpy.squeeze(arr, axis)

Example :
Code :
import numpy as np x = np.arange(25).reshape(1,5,5) print ('Array X:') print( x ) print ('\n') y = np.squeeze(x) print ('Array Y:') print( y) print ('\n') print ('The shapes of X and Y array:') print (x.shape, y.shape)

Output :