matrix_transpose

paddle. matrix_transpose ( x: paddle.Tensor, name: str | None = None ) paddle.Tensor [source]

Transpose the last two dimensions of the input tensor x.

Note

If n is the number of dimensions of x, paddle.matrix_transpose(x) is equivalent to x.transpose([0, 1, …, n-2, n-1]).

Parameters
  • x (Tensor) – The input tensor to be transposed. x must be an N-dimensional tensor (N >= 2) of any data type supported by Paddle.

  • name (str|None, optional) – The name of this layer. For more information, please refer to Name. Default is None.

Returns

A new tensor with the same shape as x, except that the last two dimensions are transposed.

Return type

Tensor

Examples

>>> import paddle
>>> x = paddle.ones(shape=[2, 3, 5])
>>> x_transposed = paddle.matrix_transpose(x)
>>> print(x_transposed.shape)
[2, 5, 3]