mindspore.ops.squeeze

View Source On Gitee
mindspore.ops.squeeze(input, axis=None)[source]

Remove length one axes from input tensor.

Note

  • Please note that in dynamic graph mode, the output tensor will share data with the input tensor, and there is no Tensor data copy process.

  • The dimension index starts at 0 and must be in the range [-input.ndim, input.ndim].

  • In GE mode, only support remove dimensions of size 1 from the shape of input tensor.

Warning

This is an experimental API that is subject to change or deletion.

Parameters
  • input (Tensor) – The input tensor.

  • axis (Union[int, tuple(int), list(int)]) – The axis to be removed. Default: None .

Returns

Tensor

Supported Platforms:

Ascend GPU CPU

Examples

>>> import mindspore
>>> input = mindspore.ops.ones(shape=[3, 2, 1])
>>> output = mindspore.ops.squeeze(input)
>>> print(output)
[[1. 1.]
 [1. 1.]
 [1. 1.]]