mindspore.numpy.squeeze

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

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

参数
  • a (Tensor) – Input tensor array.

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

返回

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

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

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

Supported Platforms:

Ascend GPU CPU

样例

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