mindspore.ops.movedim

View Source On Gitee
mindspore.ops.movedim(x, source, destination)[source]

Swap two dimensions of the input tensor.

Parameters
  • x (Tensor) – The input tensor.

  • source (Union[int, sequence[int]]) – Original dimensions.

  • destination (Union[int, sequence[int]]) – Destination positions for each of the original dimensions.

Returns

Tensor

Supported Platforms:

Ascend GPU CPU

Examples

>>> # case1 : moving single axis
>>> import mindspore
>>> x = mindspore.tensor(mindspore.ops.zeros((3, 4, 5)))
>>> output = mindspore.ops.movedim(x, 0, -1)
>>> print(output.shape)
(4, 5, 3)
>>> # case 2 : moving multiple axes
>>> x = mindspore.tensor(mindspore.ops.zeros((3, 4, 5)))
>>> output = mindspore.ops.movedim(x, (0, 2), (1, 2))
>>> print(output.shape)
(4, 3, 5)