mindspore.ops.accumulate_n

mindspore.ops.accumulate_n(x)[source]

Return the element-wise sum of all input tensors.

mindspore.ops.accumulate_n() is similar to mindspore.ops.addn(), but accumulate_n will not wait for all of its inputs to be ready before summing, which is able to reduce peak memory.

Parameters

x (Union(tuple[Tensor], list[Tensor])) – List of tensors or tuple of tensors.

Returns

Tensor

Supported Platforms:

Ascend GPU

Examples

>>> import mindspore
>>> x = mindspore.tensor([1, 2, 3], mindspore.float32)
>>> y = mindspore.tensor([4, 5, 6], mindspore.float32)
>>> output = mindspore.ops.accumulate_n([x, y, x, y])
>>> print(output)
[10. 14. 18.]