mindspore.ops.squeeze

mindspore.ops.squeeze(input, axis=None)[source]

Remove length one axes from input tensor.

Warning

Non-backward-compatible change after version 2.9.0: axis will be renamed to dim, and axis=None will be replaced by dim=() while tuple dimensions remain supported.

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].

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.]]