mindspore.ops.transpose

View Source On Gitee
mindspore.ops.transpose(input, dims)[source]

Transpose dimensions of the input tensor according to input permutation.

Note

On GPU and CPU, if the value of dims is negative, its actual value is dims[i] + rank(input). Negative value of dims is not supported on Ascend.

Parameters
  • input (Tensor) – The input tensor.

  • dims (Union[tuple[int], list[int]]) – Specify the new axis ordering.

Returns

Tensor

Supported Platforms:

Ascend GPU CPU

Examples

>>> import mindspore
>>> input = mindspore.tensor([[[1, 2, 3], [4, 5, 6]], [[7, 8, 9], [10, 11, 12]]], mindspore.float32)
>>> output = mindspore.ops.transpose(input, (0, 2, 1))
>>> print(output)
[[[ 1.  4.]
  [ 2.  5.]
  [ 3.  6.]]
 [[ 7. 10.]
  [ 8. 11.]
  [ 9. 12.]]]