mindspore.ops.swapaxes

mindspore.ops.swapaxes(input, axis0, axis1)[source]

Interchange two axes of a tensor.

Parameters
  • input (Tensor) – Input tensor.

  • axis0 (int) – First axis.

  • axis1 (int) – Second axis.

Returns

Transposed tensor, has the same data type as input.

Raises
  • TypeError – If argument input is not Tensor.

  • TypeError – If axis0 or axis1 is not integer.

  • ValueError – If axis0 or axis1 is not in the range of \([-ndim, ndim-1]\).

Supported Platforms:

Ascend GPU CPU

Examples

>>> import numpy as np
>>> import mindspore.ops as ops
>>> from mindspore import Tensor
>>> input = Tensor(np.ones((2,3,4), dtype=np.float32))
>>> output = ops.swapaxes(input, 0, 2)
>>> print(output.shape)
(4, 3, 2)