In this chapter, we will discuss about NumPy – squeeze. This function removes the one-dimensional entry from the shape of the given array. Two parameters are required for this function.
numpy.squeeze(arr, axis)
Where,
Sr.No. | Parameter & Description |
---|---|
1 | arrInput array |
2 | axisint or tuple of int. selects a subset of single-dimensional entries in the shape |
Example Of NumPy squeeze
import numpy as np x = np.arange(9).reshape(1,3,3) 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
Its output is as follows −
Array X: [[[0 1 2] [3 4 5] [6 7 8]]] Array Y: [[0 1 2] [3 4 5] [6 7 8]] The shapes of X and Y array: (1, 3, 3) (3, 3)
Next Topic – Click Here
Pingback: NumPy - Array Manipulation - Adglob Infosystem Pvt Ltd
Pingback: NumPy - expand_dims - Adglob Infosystem Pvt Ltd