mindspore.mint.cat
- mindspore.mint.cat(tensors, dim=0)[源代码]
在指定维度上拼接输入Tensor。
输入的是一个tuple或list。其元素秩相同,即
。将给定的维度设为 ,并且 。输入元素的数量设为 。对于第 个数据, 的shape为 。 是第 个元素的第 个维度。则,输出Tensor的shape为:- 参数:
tensors (Union[tuple, list]) - 输入为Tensor组成的tuple或list。假设在这个tuple或list中有两个Tensor,即 t1 和 t2 。要在第0个维度方向上执行 cat ,除第
维度外,其他维度的shape都应相等,即 ,其中 是Tensor的秩。dim (int, 可选) - 表示指定的维度,取值范围是
。默认值:0
。
- 返回:
Tensor,shape为
。数据类型与 tensors 相同。- 异常:
TypeError - dim 不是int。
ValueError - tensors 是不同维度的Tensor。
ValueError - dim 的值不在区间
内。ValueError - 除了 dim 之外, tensors 的shape不相同。
ValueError - tensors 为空tuple或list。
- 支持平台:
Ascend
样例:
>>> import mindspore >>> import numpy as np >>> from mindspore import Tensor >>> from mindspore import mint >>> input_x1 = Tensor(np.array([[0, 1], [2, 1]]).astype(np.float32)) >>> input_x2 = Tensor(np.array([[0, 1], [2, 1]]).astype(np.float32)) >>> output = mint.cat((input_x1, input_x2)) >>> print(output) [[0. 1.] [2. 1.] [0. 1.] [2. 1.]] >>> output = mint.cat((input_x1, input_x2), 1) >>> print(output) [[0. 1. 0. 1.] [2. 1. 2. 1.]]