mindspore.ops.AddN
- class mindspore.ops.AddN(*args, **kwargs)[source]
Computes addition of all input tensors element-wise.
All input tensors must have the same shape.
- Inputs:
input_x (Union(tuple[Tensor], list[Tensor])) - The input tuple or list is made up of multiple tensors whose dtype is number or bool to be added together.
- Outputs:
Tensor, has the same shape and dtype as each entry of the input_x.
- Raises
TypeError – If input_x is neither tuple nor list.
- Supported Platforms:
Ascend
GPU
CPU
Examples
>>> class NetAddN(nn.Cell): ... def __init__(self): ... super(NetAddN, self).__init__() ... self.addN = ops.AddN() ... ... def construct(self, *z): ... return self.addN(z) ... >>> net = NetAddN() >>> input_x = Tensor(np.array([1, 2, 3]), mindspore.float32) >>> input_y = Tensor(np.array([4, 5, 6]), mindspore.float32) >>> output = net(input_x, input_y, input_x, input_y) >>> print(output) [10. 14. 18.]