tf.math.add_n
Stay organized with collections
Save and categorize content based on your preferences.
Adds all input tensors element-wise.
tf.math.add_n(
inputs, name=None
)
Converts IndexedSlices
objects into dense tensors prior to adding.
tf.math.add_n
performs the same operation as tf.math.accumulate_n
, but it
waits for all of its inputs to be ready before beginning to sum.
This buffering can result in higher memory consumption when inputs are ready
at different times, since the minimum temporary storage required is
proportional to the input size rather than the output size.
This op does not broadcast
its inputs. If you need broadcasting, use tf.math.add
(or the +
operator)
instead.
For example:
a = tf.constant([[3, 5], [4, 8]])
b = tf.constant([[1, 6], [2, 9]])
tf.math.add_n([a, b, a]) # [[7, 16], [10, 25]]
Args |
inputs
|
A list of tf.Tensor or tf.IndexedSlices objects, each with same
shape and type.
|
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.add_n\n\n\u003cbr /\u003e\n\n|-----------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------|\n| [TensorFlow 1 version](/versions/r1.15/api_docs/python/tf/math/add_n) | [View source on GitHub](https://github.com/tensorflow/tensorflow/blob/v2.0.0/tensorflow/python/ops/math_ops.py#L2964-L3018) |\n\nAdds all input tensors element-wise.\n\n#### View aliases\n\n\n**Main aliases**\n\n[`tf.add_n`](/api_docs/python/tf/math/add_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.add_n`](/api_docs/python/tf/math/add_n), [`tf.compat.v1.math.add_n`](/api_docs/python/tf/math/add_n)\n\n\u003cbr /\u003e\n\n tf.math.add_n(\n inputs, name=None\n )\n\nConverts `IndexedSlices` objects into dense tensors prior to adding.\n\n[`tf.math.add_n`](../../tf/math/add_n) performs the same operation as [`tf.math.accumulate_n`](../../tf/math/accumulate_n), but it\nwaits for all of its inputs to be ready before beginning to sum.\nThis buffering can result in higher memory consumption when inputs are ready\nat different times, since the minimum temporary storage required is\nproportional to the input size rather than the output size.\n\nThis op does not [broadcast](https://docs.scipy.org/doc/numpy-1.13.0/user/basics.broadcasting.html)\nits inputs. If you need broadcasting, use [`tf.math.add`](../../tf/math/add) (or the `+` operator)\ninstead.\n\n#### For example:\n\n a = tf.constant([[3, 5], [4, 8]])\n b = tf.constant([[1, 6], [2, 9]])\n tf.math.add_n([a, b, a]) # [[7, 16], [10, 25]]\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Args ---- ||\n|----------|----------------------------------------------------------------------------------------------------------------------------------|\n| `inputs` | A list of [`tf.Tensor`](../../tf/Tensor) or [`tf.IndexedSlices`](../../tf/IndexedSlices) objects, each with same shape and type. |\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"]]