nums.numpy.squeeze

nums.numpy.squeeze(a, axis=None)[source]

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

This docstring was copied from numpy.squeeze.

Some inconsistencies with the NumS version may exist.

Parameters

a (BlockArray) – Input data.

Returns

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

Return type

BlockArray

See also

expand_dims

The inverse operation, adding singleton dimensions

reshape

Insert, remove, and combine dimensions, and resize existing ones

Notes

axis not supported.

Examples

The doctests shown below are copied from NumPy. They won’t show the correct result until you operate get().

>>> x = nps.array([[[0], [1], [2]]])  
>>> x.shape  
(1, 3, 1)
>>> nps.squeeze(x).shape  
(3,)
>>> x = nps.array([[1234]])  
>>> x.shape  
(1, 1)
>>> nps.squeeze(x).get()  
array(1234)  # 0d array
>>> nps.squeeze(x).shape  
()
>>> nps.squeeze(x)[()].get()  
array(1234)