unbind

paddle.tensor.unbind ( input, axis=0 ) [源代码]

该OP将输入Tensor按照指定的维度分割成多个子Tensor。

参数

  • input (Variable) - 输入变量,数据类型为float32,float64,int32,int64的多维Tensor。

  • axis (int32|int64,可选) - 数据类型为int32或int64,表示需要分割的维度。如果axis < 0,则划分的维度为rank(input) + axis。默认值为0。

返回:分割后的Tensor列表。

返回类型:列表(Variable),数据类型为int32,int64,float32,float64。

代码示例

  1. import paddle
  2. # input is a variable which shape is [3, 4, 5]
  3. input = paddle.fluid.data(
  4. name="input", shape=[3, 4, 5], dtype="float32")
  5. [x0, x1, x2] = paddle.tensor.unbind(input, axis=0)
  6. # x0.shape [4, 5]
  7. # x1.shape [4, 5]
  8. # x2.shape [4, 5]
  9. [x0, x1, x2, x3] = paddle.tensor.unbind(input, axis=1)
  10. # x0.shape [3, 5]
  11. # x1.shape [3, 5]
  12. # x2.shape [3, 5]
  13. # x3.shape [3, 5]