mindspore.mint.cat

查看源文件
mindspore.mint.cat(tensors, dim=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个维度方向上执行 cat ,除第 0 维度外,其他维度的shape都应相等,即 t1.shape[1]=t2.shape[1],t1.shape[2]=t2.shape[2],...,t1.shape[R1]=t2.shape[R1] ,其中 R 是Tensor的秩。

  • dim (int, 可选) - 表示指定的维度,取值范围是 [R,R) 。默认值: 0

返回:

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

异常:
  • TypeError - dim 不是int。

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

  • ValueError - dim 的值不在区间 [R,R) 内。

  • 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.]]