mindspore.ops.swapdims
- mindspore.ops.swapdims(input, dim0, dim1)[source]
Interchange two dims of a tensor. This function is equivalent to
mindspore.ops.swapaxes()
function.- Parameters
- Returns
Transposed tensor, has the same data type as input.
- Raises
TypeError – If argument input is not Tensor.
TypeError – If dim0 or dim1 is not integer.
ValueError – If dim0 or dim1 is not in the range of \([-ndim, ndim-1]\).
- Supported Platforms:
Ascend
GPU
CPU
Examples
>>> import numpy as np >>> from mindspore import ops >>> from mindspore import Tensor >>> input = Tensor(np.ones((2,3,4), dtype=np.float32)) >>> output = ops.swapdims(input, 0, 2) >>> print(output.shape) (4, 3, 2)