mindspore.ops.Concat

class mindspore.ops.Concat(axis=0)[源代码]

在指定轴上拼接输入Tensor。

输入的是一个tuple。其元素秩相同,即 R 。将给定的轴设为 m ,并且 0m<R 。输入元素的数量设为 N 。对于第 i 个数据, ti 的shape为 (x_1, x_2, …, x_{mi}, …, x_R)xmi 是第 i 个元素的第 m 个维度。则,输出tensor的shape为:

(x1,x2,...,i=1Nxmi,...,xR)

Note

“axis”的取值范围为[-dims, dims - 1]。”dims”为”input_x”的维度长度。

参数:

  • axis (int) - 表示指定的轴。默认值:0。

输入:

  • input_x (tuple, list) - 输入为Tensor组成的tuple或list。假设在这个tuple或list中有两个Tensor,即x1和x2。要在0轴方向上执行 Concat ,除0轴外,其他轴的shape都应相等,即 x1.shape[1]==x2.shape[1]x1.shape[2]==x2.shape[2]...x1.shape[R]==x2.shape[R] ,其中 R 表示最后一个轴。

输出:

Tensor,shape为 (x1,x2,...,i=1Nxmi,...,xR) 。数据类型与 input_x 相同。

异常:

  • TypeError - axis 不是int。

  • TypeError - input_x 是不同数据类型的Tensor。

  • ValueError - input_x 是不同维度的Tensor。

  • ValueError - axis 的维度范围不在[-dims, dims - 1]。

  • RuntimeError - 除了 axis 之外, input_x 的shape不相同。

支持平台:

Ascend GPU CPU

样例:

>>> input_x1 = Tensor(np.array([[0, 1], [2, 1]]).astype(np.float32))
>>> input_x2 = Tensor(np.array([[0, 1], [2, 1]]).astype(np.float32))
>>> op = ops.Concat()
>>> output = op((input_x1, input_x2))
>>> print(output)
[[0. 1.]
 [2. 1.]
 [0. 1.]
 [2. 1.]]
>>> op = ops.Concat(1)
>>> output = op((input_x1, input_x2))
>>> print(output)
[[0. 1. 0. 1.]
 [2. 1. 2. 1.]]