Returns the element-wise sum of a list of tensors. (deprecated)
View aliases
Compat aliases for migration
See Migration guide for more details.
tf.math.accumulate_n(
inputs, shape=None, tensor_dtype=None, name=None
)
Optionally, pass shape
and tensor_dtype
for shape and type checking,
otherwise, these are inferred.
For example:
a = tf.constant([[1, 2], [3, 4]])
b = tf.constant([[5, 0], [0, 6]])
tf.math.accumulate_n([a, b, a]).numpy()
array([[ 7, 4],
[ 6, 14]], dtype=int32)
# Explicitly pass shape and type
tf.math.accumulate_n(
[a, b, a], shape=[2, 2], tensor_dtype=tf.int32).numpy()
array([[ 7, 4],
[ 6, 14]], dtype=int32)
See Also:
tf.reduce_sum(inputs, axis=0)
- This performe the same mathematical operation, buttf.add_n
may be more efficient because it sums the tensors directly.reduce_sum
on the other hand callstf.convert_to_tensor
on the list of tensors, unncessairly stacking them into a single tensor before summing.tf.add_n
- This is another python wrapper for the same Op. It has nearly identical functionality.
Returns | |
---|---|
A Tensor of same shape and type as the elements of inputs .
|