t

paddle. t ( input, name=None ) [源代码]

该OP对小于等于2维的Tensor进行数据转置。0维和1维Tensor返回本身,2维Tensor等价于perm设置为0,1的 transpose 函数。

参数:

  • input (Tensor) - 输入:N维(N<=2)Tensor,可选的数据类型为float16, float32, float64, int32, int64。

  • name (str, 可选)- 该参数供开发人员打印调试信息时使用,具体用法请参见 Name ,默认值为None

返回: N维Tensor

示例:

  1. # 例1 (0-D tensor)
  2. x = tensor([0.79])
  3. paddle.t(x) = tensor([0.79])
  4. # 例2 (1-D tensor)
  5. x = tensor([0.79, 0.84, 0.32])
  6. paddle.t(x) = tensor([0.79, 0.84, 0.32])
  7. # 例3 (2-D tensor)
  8. x = tensor([0.79, 0.84, 0.32],
  9. [0.64, 0.14, 0.57])
  10. paddle.t(x) = tensor([0.79, 0.64],
  11. [0.84, 0.14],
  12. [0.32, 0.57])

代码示例:

  1. import paddle
  2. x = paddle.ones(shape=[2, 3], dtype='int32')
  3. x_transposed = paddle.t(x)
  4. print(x_transposed.shape)
  5. # [3, 2]