t

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

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

参数

  • input (Variable) - 输入:N维(N<=2)Tensor,可选的数据类型为float16, float32, float64, int32, int64。
  • name (str, 可选)- 该参数供开发人员打印调试信息时使用,具体用法请参见 Name ,默认值为None

返回

N维Tensor

返回类型

Variable

示例:

  1. # 例1 (0-D tensor)
  2. x = tensor([0.79])
  3. fluid.layers.t(x) = tensor([0.79])
  4. # 例2 (1-D tensor)
  5. x = tensor([0.79, 0.84, 0.32])
  6. fluid.layers.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. fluid.layers.t(x) = tensor([0.79, 0.64],
  11. [0.84, 0.14],
  12. [0.32, 0.57])

代码示例

  1. import paddle
  2. import paddle.fluid as fluid
  3. x = fluid.data(name='x', shape=[2, 3], dtype='float32')
  4. x_transposed = fluid.layers.t(x)
  5. print(x_transposed.shape)
  6. #(3L, 2L)