mindspore.ops.cat

查看源文件
mindspore.ops.cat(tensors, axis=0)[源代码]

在指定轴上拼接输入Tensor。

输入为tuple或list,其中所有元素的秩相同,记为 R 。设定拼接轴为 m ,且满足 0m<R 。假设输入元素数量为 N ,第 i 个元素 ti 的shape为 (x1,x2,...,xmi,...,xR) ,其中 xmi 是第 ti 个元素的第 m 个维度。则输出Tensor的shape为:

(x1,x2,...,i=1Nxmi,...,xR)
参数:
  • tensors (Union[tuple, list]) - 输入为Tensor组成的tuple或list。假设在这个tuple或list中有两个Tensor,即 t1t2 。要在0轴方向上执行 Concat ,除 0 轴外,其他轴的shape都应相等,即 t1.shape[1]=t2.shape[1],t1.shape[2]=t2.shape[2],...,t1.shape[R1]=t2.shape[R1] ,其中 R 是Tensor的秩。

  • axis (int) - 表示指定的轴,取值范围是 [R,R) 。默认值: 0

返回:

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

异常:
  • TypeError - axis 不是int。

  • ValueError - tensors 中的Tensor维度不同。

  • ValueError - axis 的值不在 [R,R) 范围内。

  • ValueError - 除了 axis 之外, tensors 的shape不相同。

  • ValueError - tensors 为空tuple或list。

支持平台:

Ascend GPU CPU

样例:

>>> import mindspore
>>> import numpy as np
>>> from mindspore import Tensor, ops
>>> 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 = ops.cat((input_x1, input_x2))
>>> print(output)
[[0. 1.]
 [2. 1.]
 [0. 1.]
 [2. 1.]]
>>> output = ops.cat((input_x1, input_x2), 1)
>>> print(output)
[[0. 1. 0. 1.]
 [2. 1. 2. 1.]]