concat

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

Concat

This OP concatenates the input along the axis.

Parameters
  • input (list) – List of input Tensors with data type float32, float64, int32, int64.

  • axis (int32|Variable, optional) – A scalar with type int32 or a Tensor with shape [1] and type int32. Axis to compute indices along. 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’s.

Return type

Variable

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)
    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]]