mindspore.ops.AddN

class mindspore.ops.AddN[source]

Computes addition of all input tensors element-wise.

Refer to mindspore.ops.addn() for more details.

Inputs:
  • x (Union(tuple[Tensor], list[Tensor])) - A tuple or list composed of Tensor, the data type is bool_ or number .

Outputs:

Tensor, has the same shape and dtype as each Tensor of x.

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()
>>> x = Tensor(np.array([1, 2, 3]), mindspore.float32)
>>> y = Tensor(np.array([4, 5, 6]), mindspore.float32)
>>> output = net(x, y, x, y)
>>> print(output)
[10. 14. 18.]