mindspore.ops.movedim

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

Moves axis of an array from source to destination.

Other axis remain in their original order.

Parameters
  • x (Tensor) – The tensor array whose axis should be reordered. The dimension of x must not be 0.

  • source (Union[int, sequence[int]]) – Original positions of the axis to move. The length of source and destination must be the same.

  • destination (Union[int, sequence[int]]) – Destination positions for each of the original axis. The length of source and destination must be the same.

Returns

Tensor, array with moved axis.

Raises

ValueError – If axis are out of the range of [-x.ndim, x.ndim), or if the axis contain duplicates.

Supported Platforms:

Ascend GPU CPU

Examples

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