moveaxis

paddle. moveaxis ( x, source, destination, name=None ) [source]

Move the axis of tensor from source position to destination position.

Other axis that have not been moved remain their original order.

Parameters
  • x (Tensor) – The input Tensor. It is a N-D Tensor of data types bool, int32, int64, float32, float64, complex64, complex128.

  • source (int|tuple|list) – source position of axis that will be moved. Each element must be unique and integer.

  • destination (int|tuple|list(int)) – destination position of axis that has been moved. Each element must be unique and integer.

  • name (str, optional) – The default value is None. Normally there is no need for user to set this property. For more information, please refer to Name.

Returns

A new tensor whose axis have been moved.

Return type

Tensor

Examples

import paddle

x = paddle.ones([3, 2, 4])
paddle.moveaxis(x, [0, 1], [1, 2]).shape
# [4, 3, 2]

x = paddle.ones([2, 3])
paddle.moveaxis(x, 0, 1) # equivalent to paddle.t(x)
# [3, 2]