megengine.functional.swapaxes

swapaxes(inp, axis1, axis2)[源代码]

Interchange two axes of a tensor.

参数
  • inp (Tensor) – input tensor to swapaxes.

  • axis1 (int) – first axis.

  • axis2 (int) – second axis.

返回类型

Tensor

返回

a tensor after swapping the two axes of ‘inp’.

实际案例

>>> x = Tensor(np.array([[[0,1],[2,3]],[[4,5],[6,7]]], dtype=np.int32))
>>> F.swapaxes(x, 0, 2)
Tensor([[[0 4]
 [2 6]]
[[1 5]
 [3 7]]], dtype=int32, device=xpux:0)