mindspore.ops.cat
- mindspore.ops.cat(tensors, axis=0)[源代码]
在指定轴上拼接输入Tensor。
输入为tuple或list,其中所有元素的秩相同,记为
。设定拼接轴为 ,且满足 。假设输入元素数量为 ,第 个元素 的shape为 ,其中 是第 个元素的第 个维度。则输出Tensor的shape为:- 参数:
tensors (Union[tuple, list]) - 输入为Tensor组成的tuple或list。假设在这个tuple或list中有两个Tensor,即 t1 和 t2 。要在0轴方向上执行 Concat ,除
轴外,其他轴的shape都应相等,即 ,其中 是Tensor的秩。axis (int) - 表示指定的轴,取值范围是
。默认值:0
。
- 返回:
Tensor,shape为
,数据类型与 tensors 相同。- 异常:
TypeError - axis 不是int。
ValueError - tensors 中的Tensor维度不同。
ValueError - axis 的值不在
范围内。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.]]