tf.accumulate_n
tf.accumulate_n
tf.accumulate_n
accumulate_n( inputs, shape=None, tensor_dtype=None, name=None )
Defined in tensorflow/python/ops/math_ops.py
.
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.
NOTE: This operation is not differentiable and cannot be used if inputs depend on trainable variables. Please use tf.add_n
for such cases.
Aside from differentiability, 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.
For example:
# tensor 'a' is [[1, 2], [3, 4]] # tensor `b` is [[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]]
Args:
-
inputs
: A list ofTensor
objects, each with same shape and type. -
shape
: Shape of elements ofinputs
. -
tensor_dtype
: The type ofinputs
. -
name
: A name for the operation (optional).
Returns:
A Tensor
of same shape and type as the elements of inputs
.
Raises:
-
ValueError
: Ifinputs
don't all have same shape and dtype or the shape cannot be inferred.
© 2017 The TensorFlow Authors. All rights reserved.
Licensed under the Creative Commons Attribution License 3.0.
Code samples licensed under the Apache 2.0 License.
https://www.tensorflow.org/api_docs/python/tf/accumulate_n