t

paddle. t ( input, name=None ) [source]

Transpose <=2-D tensor. 0-D and 1-D tensors are returned as it is and 2-D tensor is equal to the paddle.transpose function which perm dimensions set 0 and 1.

Parameters
  • input (Tensor) – The input Tensor. It is a N-D (N<=2) Tensor of data types float32, float64, int32, int64.

  • 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 transposed n-D Tensor, with data type being float16, float32, float64, int32, int64.

Return type

Tensor

Examples

>>> import paddle

>>> # Example 1 (0-D tensor)
>>> x = paddle.to_tensor([0.79])
>>> out = paddle.t(x)
>>> print(out)
Tensor(shape=[1], dtype=float32, place=Place(cpu), stop_gradient=True,
[0.79000002])

>>> # Example 2 (1-D tensor)
>>> x = paddle.to_tensor([0.79, 0.84, 0.32])
>>> out2 = paddle.t(x)
>>> print(out2)
Tensor(shape=[3], dtype=float32, place=Place(cpu), stop_gradient=True,
[0.79000002, 0.83999997, 0.31999999])
>>> print(paddle.t(x).shape)
[3]

>>> # Example 3 (2-D tensor)
>>> x = paddle.to_tensor([[0.79, 0.84, 0.32],
...                       [0.64, 0.14, 0.57]])
>>> print(x.shape)
[2, 3]
>>> out3 = paddle.t(x)
>>> print(out3)
Tensor(shape=[3, 2], dtype=float32, place=Place(cpu), stop_gradient=True,
[[0.79000002, 0.63999999],
 [0.83999997, 0.14000000],
 [0.31999999, 0.56999999]])
>>> print(paddle.t(x).shape)
[3, 2]