mindspore.numpy.squeeze

mindspore.numpy.squeeze(a, axis=None)[源代码]

Removes single-dimensional entries from the shape of a tensor.

Parameters
  • a (Tensor) – Input tensor array.

  • axis (Union[None, int, list(int), tuple(list)]) – The axis(axes) to squeeze, default is None.

Returns

Tensor, with all or a subset of the dimensions of length \(1\) removed.

Raises
  • TypeError – If input arguments have types not specified above.

  • ValueError – If specified axis has shape entry \(> 1\).

Supported Platforms:

Ascend GPU CPU

Examples

>>> import mindspore.numpy as np
>>> x = np.ones((1,2,2,1))
>>> x = np.squeeze(x)
>>> print(x.shape)
(2, 2)