dpnp.squeeze

dpnp.squeeze(a, /, axis=None)[source]

Removes singleton dimensions (axes) from array a.

For full documentation refer to numpy.squeeze.

Parameters:
  • a ({dpnp.ndarray, usm_ndarray}) -- Input data.

  • axis (None or int or tuple of ints, optional) -- 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.

Returns:

out -- Output array is a view, if possible, and a copy otherwise, but with all or a subset of the dimensions of length 1 removed. Output has the same data type as the input, is allocated on the same device as the input and has the same USM allocation type as the input array a.

Return type:

dpnp.ndarray

Examples

>>> import dpnp as np
>>> x = np.array([[[0], [1], [2]]])
>>> x.shape
(1, 3, 1)
>>> np.squeeze(x).shape
(3,)
>>> np.squeeze(x, axis=0).shape
(3, 1)
>>> 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.
>>> np.squeeze(x, axis=2).shape
(1, 3)