megengine.functional.swapaxes#

swapaxes(inp, axis1, axis2)[source]#

Interchange two axes of a tensor.

Parameters:
  • inp (Tensor) – input tensor to swapaxes.

  • axis1 (int) – first axis.

  • axis2 (int) – second axis.

Return type:

Tensor

Returns:

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

Examples

>>> 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)