tf.math.accumulate_n
Stay organized with collections
Save and categorize content based on your preferences.
Returns the element-wise sum of a list of tensors.
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.
accumulate_n
performs the same operation as tf.math.add_n
, but
does not wait for all of its inputs to be ready before beginning to sum.
This approach 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.math.accumulate_n([a, b, a]) # [[7, 4], [6, 14]]
# Explicitly pass shape and type
tf.math.accumulate_n([a, b, a], shape=[2, 2], tensor_dtype=tf.int32)
# [[7, 4],
# [6, 14]]
Args |
inputs
|
A list of Tensor objects, each with same shape and type.
|
shape
|
Expected shape of elements of inputs (optional). Also controls the
output shape of this op, which may affect type inference in other ops. A
value of None means "infer the input shape from the shapes in inputs ".
|
tensor_dtype
|
Expected data type of inputs (optional). A value of None
means "infer the input dtype from inputs[0] ".
|
name
|
A name for the operation (optional).
|
Returns |
A Tensor of same shape and type as the elements of inputs .
|
Raises |
ValueError
|
If inputs don't all have same shape and dtype or the shape
cannot be inferred.
|
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2020-10-01 UTC.
[null,null,["Last updated 2020-10-01 UTC."],[],[],null,["# tf.math.accumulate_n\n\n\u003cbr /\u003e\n\n|---------------------------------------------------------------|------------------------------------------------------------------------------------------------------------------------------|\n| [TensorFlow 2 version](/api_docs/python/tf/math/accumulate_n) | [View source on GitHub](https://github.com/tensorflow/tensorflow/blob/v1.15.0/tensorflow/python/ops/math_ops.py#L3010-L3091) |\n\nReturns the element-wise sum of a list of tensors.\n\n#### View aliases\n\n\n**Main aliases**\n\n\\`tf.accumulate_n\\`\n**Compat aliases for migration**\n\nSee\n[Migration guide](https://www.tensorflow.org/guide/migrate) for\nmore details.\n\n[`tf.compat.v1.accumulate_n`](/api_docs/python/tf/math/accumulate_n), [`tf.compat.v1.math.accumulate_n`](/api_docs/python/tf/math/accumulate_n), \\`tf.compat.v2.math.accumulate_n\\`\n\n\u003cbr /\u003e\n\n tf.math.accumulate_n(\n inputs, shape=None, tensor_dtype=None, name=None\n )\n\nOptionally, pass `shape` and `tensor_dtype` for shape and type checking,\notherwise, these are inferred.\n\n`accumulate_n` performs the same operation as [`tf.math.add_n`](../../tf/math/add_n), but\ndoes not wait for all of its inputs to be ready before beginning to sum.\nThis approach can save memory if inputs are ready at different times, since\nminimum temporary storage is proportional to the output size rather than the\ninputs' size.\n\n`accumulate_n` is differentiable (but wasn't previous to TensorFlow 1.7).\n\n#### For example:\n\n a = tf.constant([[1, 2], [3, 4]])\n b = tf.constant([[5, 0], [0, 6]])\n tf.math.accumulate_n([a, b, a]) # [[7, 4], [6, 14]]\n\n # Explicitly pass shape and type\n tf.math.accumulate_n([a, b, a], shape=[2, 2], tensor_dtype=tf.int32)\n # [[7, 4],\n # [6, 14]]\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Args ---- ||\n|----------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| `inputs` | A list of `Tensor` objects, each with same shape and type. |\n| `shape` | Expected shape of elements of `inputs` (optional). Also controls the output shape of this op, which may affect type inference in other ops. A value of `None` means \"infer the input shape from the shapes in `inputs`\". |\n| `tensor_dtype` | Expected data type of `inputs` (optional). A value of `None` means \"infer the input dtype from `inputs[0]`\". |\n| `name` | A name for the operation (optional). |\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Returns ------- ||\n|---|---|\n| A `Tensor` of same shape and type as the elements of `inputs`. ||\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Raises ------ ||\n|--------------|----------------------------------------------------------------------------------|\n| `ValueError` | If `inputs` don't all have same shape and dtype or the shape cannot be inferred. |\n\n\u003cbr /\u003e"]]