This is documentation for an old release of NumPy (version 1.6.0). Read this page in the documentation of the latest stable release (version > 1.17).

numpy.squeeze

numpy.squeeze(a)

Remove single-dimensional entries from the shape of an array.

Parameters :

a : array_like

Input data.

Returns :

squeezed : ndarray

The input array, but with with all dimensions of length 1 removed. Whenever possible, a view on a is returned.

Examples

>>> x = np.array([[[0], [1], [2]]])
>>> x.shape
(1, 3, 1)
>>> np.squeeze(x).shape
(3,)

Previous topic

numpy.expand_dims

Next topic

numpy.asarray

This Page