- numpy.squeeze(a, axis=None)¶
Remove single-dimensional entries from the shape of an array.
a : array_like
axis : None or int or tuple of ints, optional
New in version 1.7.0.
Selects a subset of the single-dimensional entries in the shape. If an axis is selected with shape entry greater than one, an error is raised.
squeezed : ndarray
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.
>>> x = np.array([[, , ]]) >>> x.shape (1, 3, 1) >>> np.squeeze(x).shape (3,) >>> np.squeeze(x, axis=(2,)).shape (1, 3)