concat¶
- paddle. concat ( x: Sequence[Tensor], axis: int | Tensor = 0, name: str | None = None ) Tensor [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.
The image illustrates a typical case of the concat operation. Two three-dimensional tensors with shapes [2, 3, 4] are concatenated along different axes, resulting in tensors of different shapes. The effects of concatenation along various dimensions are clearly visible.
- Parameters
-
x (list|tuple) –
x
is a Tensor list or Tensor tuple which is with data type bool, float16, bfloat16, float32, float64, int8, int16, int32, int64, uint8, uint16, complex64, complex128. All the Tensors inx
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 asaxis+R
. Default is 0.name (str|None, 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]])