unbind

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

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

参数

  • input (Tensor) - 输入变量,数据类型为 float16、loat32、float64、int32、int64、complex64、complex128 的多维 Tensor。

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

返回

Tensor,分割后的 Tensor 列表。

代码示例

>>> import paddle

>>> # input is a Tensor which shape is [3, 4, 5]
>>> input = paddle.rand([3, 4, 5])

>>> [x0, x1, x2] = paddle.unbind(input, axis=0)
>>> # x0.shape [4, 5]
>>> # x1.shape [4, 5]
>>> # x2.shape [4, 5]

>>> [x0, x1, x2, x3] = paddle.unbind(input, axis=1)
>>> # x0.shape [3, 5]
>>> # x1.shape [3, 5]
>>> # x2.shape [3, 5]
>>> # x3.shape [3, 5]