mindspore.Tensor.unbind
- mindspore.Tensor.unbind(dim=0)
根据指定轴对Tensor进行分解。给定shape为 \((n_1, n_2, ..., n_R)\) 的 self Tensor,在指定 dim 上对其分解, 则返回多个shape为 \((n_1, n_2, ..., n_{dim}, n_{dim+2}, ..., n_R)\) 的Tensor。
- 参数:
dim (int,可选) - 用以分解的维度。取值范围为[-R, R)。默认值为
0
。
- 返回:
Tensor组成的tuple。每个Tensor对象的shape相同。
- 异常:
TypeError - 如果 dim 不是int类型。
ValueError - 如果 dim 超出[-R, R)范围。
- 支持平台:
Ascend
GPU
CPU
样例:
>>> import numpy as np >>> from mindspore import Tensor >>> input = Tensor(np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9]])) >>> output = input.unbind(dim=0) >>> print(output) (Tensor(shape=[3], dtype=Int64, value=[1, 2, 3]), Tensor(shape=[3], dtype=Int64, value=[4, 5, 6]), Tensor(shape=[3], dtype=Int64, value=[7, 8, 9]))