# sum¶

paddle.fluid.layers. sum ( x ) [源代码]

```输入：
input.shape = [2, 3]
input = [[1, 2, 3],
[4, 5, 6]]

output.shape = [2, 3]
output = [[1, 2, 3],
[4, 5, 6]]
```

```输入：
第一个输入：
input1.shape = [2, 3]
input1 = [[1, 2, 3],
[4, 5, 6]]

第二个输入：
input2.shape = [2, 3]
input2 = [[7, 8, 9],
[10, 11, 12]]

output.shape = [2, 3]
output = [[8, 10, 12],
[14, 16, 18]]
```

## 参数¶

x (Variable|list(Variable)) - 输入的一至多个Variable。如果输入了多个Variable，则不同Variable间的shape和数据类型应保持一致。Variable为多维Tensor或LoDTensor，数据类型支持：float32，float64，int32，int64

Variable

## 代码示例¶

```import paddle.fluid as fluid

input0 = fluid.layers.fill_constant(shape=[2, 3], dtype='int64', value=5)
input1 = fluid.layers.fill_constant(shape=[2, 3], dtype='int64', value=3)
sum = fluid.layers.sum([input0, input1])

# You can print out 'sum' via executor.
out = fluid.layers.Print(sum, message="the sum of input0 and input1: ")
exe = fluid.Executor(fluid.CPUPlace())
exe.run(fluid.default_main_program())

# The printed result is:
# 1570701754        the sum of input0 and input1:   The place is:CPUPlace
# Tensor[sum_0.tmp_0]
#    shape: [2,3,]
#    dtype: l
#    data: 8,8,8,8,8,8,

# the sum of input0 and input1 is 2-D Tensor with shape [2,3].
# dtype is the corresponding C++ data type, which may vary in different environments.
# Eg: if the data type of tensor is int64, then the corresponding C++ data type is int64_t,
#       so the dtype value is typeid(int64_t).Name(), which is 'x' on MacOS, 'l' on Linux,
#       and '__int64' on Windows. They both represent 64-bit integer variables.
```