mars.tensor.transpose#

mars.tensor.transpose(a, axes=None)[source]#

Permute the dimensions of a tensor.

Parameters
  • a (array_like) – Input tensor.

  • axes (list of ints, optional) – By default, reverse the dimensions, otherwise permute the axes according to the values given.

Returns

pa with its axes permuted. A view is returned whenever possible.

Return type

Tensor

See also

moveaxis, argsort

Notes

Use transpose(a, argsort(axes)) to invert the transposition of tensors when using the axes keyword argument.

Transposing a 1-D array returns an unchanged view of the original tensor.

Examples

>>> import mars.tensor as mt
>>> x = mt.arange(4).reshape((2,2))
>>> x.execute()
array([[0, 1],
       [2, 3]])
>>> mt.transpose(x).execute()
array([[0, 2],
       [1, 3]])
>>> x = mt.ones((1, 2, 3))
>>> mt.transpose(x, (1, 0, 2)).shape
(2, 1, 3)