mindspore.ops.expand_dims

View Source On Gitee
mindspore.ops.expand_dims(input_x, axis)[source]

Adds an additional axis to input tensor.

Note

  • The dimension of input_x should be greater than or equal to 1.

  • If the specified axis is a negative number, the index is counted backward from the end and starts at 1.

Parameters
  • input_x (Tensor) – The input tensor.

  • axis (int) – The newly added axis. Only constant value is allowed.

Returns

Tensor

Supported Platforms:

Ascend GPU CPU

Examples

>>> import mindspore
>>> input_tensor = mindspore.tensor([[2, 2], [2, 2]], mindspore.float32)
>>> output = mindspore.ops.expand_dims(input_tensor, 0)
>>> print(output)
[[[2. 2.]
  [2. 2.]]]