add_n¶
- paddle. add_n ( inputs, name=None ) [source]
-
Sum one or more Tensor of the input.
For example:
Case 1: Input: input.shape = [2, 3] input = [[1, 2, 3], [4, 5, 6]] Output: output.shape = [2, 3] output = [[1, 2, 3], [4, 5, 6]] Case 2: Input: First input: input1.shape = [2, 3] Input1 = [[1, 2, 3], [4, 5, 6]] The second input: input2.shape = [2, 3] input2 = [[7, 8, 9], [10, 11, 12]] Output: output.shape = [2, 3] output = [[8, 10, 12], [14, 16, 18]]
- Parameters
-
inputs (Tensor|list[Tensor]|tuple[Tensor]) – A Tensor or a list/tuple of Tensors. The shape and data type of the list/tuple elements should be consistent. Input can be multi-dimensional Tensor, and data types can be: float32, float64, int32, int64, complex64, complex128.
name (str, optional) – Name for the operation (optional, default is None). For more information, please refer to Name.
- Returns
-
Tensor, the sum of input \(inputs\) , its shape and data types are consistent with \(inputs\).
Examples
>>> import paddle >>> input0 = paddle.to_tensor([[1, 2, 3], [4, 5, 6]], dtype='float32') >>> input1 = paddle.to_tensor([[7, 8, 9], [10, 11, 12]], dtype='float32') >>> output = paddle.add_n([input0, input1]) >>> output Tensor(shape=[2, 3], dtype=float32, place=Place(cpu), stop_gradient=True, [[8. , 10., 12.], [14., 16., 18.]])