moveaxis

paddle. moveaxis ( x: Tensor, source: int | Sequence[int], destination: int | Sequence[int], name: str | None = None ) Tensor [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) – destination position of axis that has been moved. Each element must be unique and integer.

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

Returns

Tensor, A new tensor whose axis have been moved.

Examples

>>> import paddle >>> x = paddle.ones([3, 2, 4]) >>> outshape = paddle.moveaxis(x, [0, 1], [1, 2]).shape >>> print(outshape) [4, 3, 2] >>> x = paddle.ones([2, 3]) >>> outshape = paddle.moveaxis(x, 0, 1).shape # equivalent to paddle.t(x) >>> print(outshape) [3, 2]