concat

paddle. concat ( x, axis=0, name=None ) [source]

Concatenates the input along the axis. It doesn’t support 0-D Tensor because it requires a certain axis, and 0-D Tensor doesn’t have any axis.

Parameters
  • x (list|tuple) – x is a Tensor list or Tensor tuple which is with data type bool, float16, float32, float64, int32, int64, int8, uint8. All the Tensors in x must have same data type.

  • axis (int|Tensor, optional) – Specify the axis to operate on the input Tensors. Tt should be integer or 0-D int Tensor with shape []. The effective range is [-R, R), where R is Rank(x). When axis < 0, it works the same way as axis+R. Default is 0.

  • name (str, optional) – Name for the operation (optional, default is None). For more information, please refer to Name.

Returns

Tensor, A Tensor with the same data type as x.

Examples

>>> import paddle

>>> x1 = paddle.to_tensor([[1, 2, 3],
...                        [4, 5, 6]])
>>> x2 = paddle.to_tensor([[11, 12, 13],
...                        [14, 15, 16]])
>>> x3 = paddle.to_tensor([[21, 22],
...                        [23, 24]])
>>> zero = paddle.full(shape=[1], dtype='int32', fill_value=0)
>>> # When the axis is negative, the real axis is (axis + Rank(x))
>>> # As follow, axis is -1, Rank(x) is 2, the real axis is 1
>>> out1 = paddle.concat(x=[x1, x2, x3], axis=-1)
>>> out2 = paddle.concat(x=[x1, x2], axis=0)
>>> out3 = paddle.concat(x=[x1, x2], axis=zero)
>>> print(out1)
Tensor(shape=[2, 8], dtype=int64, place=Place(cpu), stop_gradient=True,
[[1 , 2 , 3 , 11, 12, 13, 21, 22],
 [4 , 5 , 6 , 14, 15, 16, 23, 24]])
>>> print(out2)
Tensor(shape=[4, 3], dtype=int64, place=Place(cpu), stop_gradient=True,
[[1 , 2 , 3 ],
 [4 , 5 , 6 ],
 [11, 12, 13],
 [14, 15, 16]])
>>> print(out3)
Tensor(shape=[4, 3], dtype=int64, place=Place(cpu), stop_gradient=True,
[[1 , 2 , 3 ],
 [4 , 5 , 6 ],
 [11, 12, 13],
 [14, 15, 16]])