mindspore.mint.cat
- mindspore.mint.cat(tensors, dim=0)[source]
Connect input tensors along with the given dimension.
The input data is a tuple or a list of tensors. These tensors have the same rank
. Set the given dimension as , and . Set the number of input tensors as . For the -th tensor , it has the shape of . is the -th dimension of the . Then, the shape of the output tensor is- Parameters
tensors (Union[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 dimension 0 direction, except for the
-th dimension, all other dimensions should be equal, that is, , where represents the rank of tensor.dim (int, optional) – The specified dimension, whose value is in range
. Default:0
.
- Returns
Tensor, the shape is
. The data type is the same with tensors.- Raises
TypeError – If dim is not an int.
ValueError – If tensors have different dimension of tensor.
ValueError – If dim not in range
.ValueError – If tensor's shape in tensors except for dim are different.
ValueError – If tensors is an empty tuple or list.
- Supported Platforms:
Ascend
Examples
>>> 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.]]