mindspore.ops.concat

mindspore.ops.concat(input_x, axis=0)[source]

Connect input tensors along with the given axis.

The input data is a tuple of tensors. These tensors have the same rank \(R\). Set the given axis as \(m\), and \(0 \le m < R\). Set the number of input tensors as \(N\). For the \(i\)-th tensor \(t_i\), it has the shape of \((x_1, x_2, ..., x_{mi}, ..., x_R)\). \(x_{mi}\) is the \(m\)-th dimension of the \(t_i\). Then, the shape of the output tensor is

\[(x_1, x_2, ..., \sum_{i=1}^Nx_{mi}, ..., x_R)\]
Parameters
  • input_x (tuple, list) – A tuple or a list of input tensors. Suppose there are two tensors in this tuple or list, namely t1 and t2. To perform concat in the axis 0 direction, except for the \(0\)-th axis, all other dimensions should be equal, that is, \(t1.shape[1] = t2.shape[1], t1.shape[2] = t2.shape[2], ..., t1.shape[R-1] = t2.shape[R-1]\),

  • axis (int) – The specified axis, whose value is in range \([-R, R)\). Default: 0.

Returns

Tensor, the shape is \((x_1, x_2, ..., \sum_{i=1}^Nx_{mi}, ..., x_R)\).

The data type is the same with input_x.

Raises
  • TypeError – If axis is not an int.

  • ValueError – If input_x have different dimension of tensor.

  • ValueError – If axis not in range \([-R, R)\).

  • RuntimeError – If tensor’s shape in input_x except for axis are different.

Supported Platforms:

Ascend GPU CPU

Examples

>>> 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.concat((input_x1, input_x2))
>>> print(output)
[[0. 1.]
 [2. 1.]
 [0. 1.]
 [2. 1.]]
>>> output = ops.concat((input_x1, input_x2), 1)
>>> print(output)
[[0. 1. 0. 1.]
 [2. 1. 2. 1.]]