concat

paddle.fluid.layers.tensor. concat ( input, axis=0, name=None ) [source]

This OP concatenates the input along the axis.

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

  • axis (int|Tensor, optional) – Specify the axis to operate on the input Tensors. It’s a scalar with data type int or a Tensor with shape [1] and data type int32 or int64. 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) – The default value is None. Normally there is no need for user to set this property. For more information, please refer to Name.

Returns

A Tensor with the same data type as input.

Return type

Tensor

Examples

import paddle.fluid as fluid
import numpy as np

in1 = np.array([[1, 2, 3],
                [4, 5, 6]])
in2 = np.array([[11, 12, 13],
                [14, 15, 16]])
in3 = np.array([[21, 22],
                [23, 24]])
with fluid.dygraph.guard():
    x1 = fluid.dygraph.to_variable(in1)
    x2 = fluid.dygraph.to_variable(in2)
    x3 = fluid.dygraph.to_variable(in3)
    # When the axis is negative, the real axis is (axis + Rank(x)).
    # As follows, axis is -1, Rank(x) is 2, the real axis is 1
    out1 = fluid.layers.concat(input=[x1, x2, x3], axis=-1)
    out2 = fluid.layers.concat(input=[x1, x2], axis=0)
    print(out1.numpy())
    # [[ 1  2  3 11 12 13 21 22]
    #  [ 4  5  6 14 15 16 23 24]]
    print(out2.numpy())
    # [[ 1  2  3]
    #  [ 4  5  6]
    #  [11 12 13]
    #  [14 15 16]]