numpy 1.22.4 Pypi GitHub Homepage
Other Docs
ParametersRaisesReturnsBackRef
squeeze(a, axis=None)

Parameters

a : array_like

Input data.

axis : None or int or tuple of ints, optional
versionadded

Selects a subset of the entries of length one in the shape. If an axis is selected with shape entry greater than one, an error is raised.

Raises

ValueError

If :None:None:`axis` is not None, and an axis being squeezed is not of length 1

Returns

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. Note that if all axes are squeezed, the result is a 0d array and not a scalar.

Remove axes of length one from a.

See Also

expand_dims

The inverse operation, adding entries of length one

reshape

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

Examples

This example is valid syntax, but we were not able to check execution
>>> x = np.array([[[0], [1], [2]]])
... x.shape (1, 3, 1)
This example is valid syntax, but we were not able to check execution
>>> np.squeeze(x).shape
(3,)
This example is valid syntax, but we were not able to check execution
>>> np.squeeze(x, axis=0).shape
(3, 1)
This example is valid syntax, but we were not able to check execution
>>> np.squeeze(x, axis=1).shape
Traceback (most recent call last):
...
ValueError: cannot select an axis to squeeze out which has size not equal to one
This example is valid syntax, but we were not able to check execution
>>> np.squeeze(x, axis=2).shape
(1, 3)
This example is valid syntax, but we were not able to check execution
>>> x = np.array([[1234]])
... x.shape (1, 1)
This example is valid syntax, but we were not able to check execution
>>> np.squeeze(x)
array(1234)  # 0d array
This example is valid syntax, but we were not able to check execution
>>> np.squeeze(x).shape
()
This example is valid syntax, but we were not able to check execution
>>> np.squeeze(x)[()]
1234
See :

Back References

The following pages refer to to this document either explicitly or contain code examples using this.

scipy.signal._ltisys.dstep numpy.matrixlib.defmatrix.matrix.squeeze dask.array.core.Array.squeeze dask.array.routines.squeeze scipy.signal._ltisys.dimpulse scipy.signal._lti_conversion.cont2discrete numpy.expand_dims

Local connectivity graph

Hover to see nodes names; edges to Self not shown, Caped at 50 nodes.

Using a canvas is more power efficient and can get hundred of nodes ; but does not allow hyperlinks; , arrows or text (beyond on hover)

SVG is more flexible but power hungry; and does not scale well to 50 + nodes.

All aboves nodes referred to, (or are referred from) current nodes; Edges from Self to other have been omitted (or all nodes would be connected to the central node "self" which is not useful). Nodes are colored by the library they belong to, and scaled with the number of references pointing them


GitHub : /numpy/core/fromnumeric.py#1478
type: <class 'function'>
Commit: