Defined in tensorflow/python/ops/

See the guide: Math > Reduction

Returns the element-wise sum of a list of tensors.

Optionally, pass shape and tensor_dtype for shape and type checking, otherwise, these are inferred.

tf.accumulate_n performs the same operation as tf.add_n, but does not wait for all of its inputs to be ready before beginning to sum. This can save memory if inputs are ready at different times, since minimum temporary storage is proportional to the output size rather than the inputs size.

accumulate_n is differentiable (but wasn't previous to TensorFlow 1.7).

For example:

a = tf.constant([[1, 2], [3, 4]])
b = tf.constant([[5, 0], [0, 6]])
tf.accumulate_n([a, b, a])  # [[7, 4], [6, 14]]

# Explicitly pass shape and type
tf.accumulate_n([a, b, a], shape=[2, 2], tensor_dtype=tf.int32)
                                                               # [[7,  4],
                                                               #  [6, 14]]


  • inputs: A list of Tensor objects, each with same shape and type.
  • shape: Shape of elements of inputs.
  • tensor_dtype: The type of inputs.
  • name: A name for the operation (optional).


A Tensor of same shape and type as the elements of inputs.


  • ValueError: If inputs don't all have same shape and dtype or the shape cannot be inferred.