# tf.math.add_n

<br />

|---|
| [![](https://www.tensorflow.org/images/GitHub-Mark-32px.png) View source on GitHub](https://github.com/tensorflow/tensorflow/blob/v2.14.0/tensorflow/python/ops/math_ops.py#L4098-L4155) |

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

#### View aliases


**Main aliases**

[`tf.add_n`](https://www.tensorflow.org/api_docs/python/tf/math/add_n)
**Compat aliases for migration**

See
[Migration guide](https://www.tensorflow.org/guide/migrate) for
more details.

[`tf.compat.v1.add_n`](https://www.tensorflow.org/api_docs/python/tf/math/add_n), [`tf.compat.v1.math.add_n`](https://www.tensorflow.org/api_docs/python/tf/math/add_n)

<br />

    tf.math.add_n(
        inputs, name=None
    )

All inputs in the list must have the same shape. This op does not
[broadcast](https://docs.scipy.org/doc/numpy-1.13.0/user/basics.broadcasting.html)
its inputs. If you need broadcasting, use [`tf.math.add`](https://www.tensorflow.org/versions/r2.14/api_docs/python/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]).numpy()
    array([[ 7, 16],
           [10, 25]], dtype=int32)

#### See Also:

- [`tf.reduce_sum(inputs, axis=0)`](https://www.tensorflow.org/versions/r2.14/api_docs/python/tf/math/reduce_sum) - This performs the same mathematical operation, but [`tf.add_n`](https://www.tensorflow.org/versions/r2.14/api_docs/python/tf/math/add_n) may be more efficient because it sums the tensors directly. `reduce_sum` on the other hand calls [`tf.convert_to_tensor`](https://www.tensorflow.org/versions/r2.14/api_docs/python/tf/convert_to_tensor) on the list of tensors, unnecessarily stacking them into a single tensor before summing.

<br />

<br />

<br />

| ## Args ||
|---|---|
| `inputs` | A list of [`tf.Tensor`](https://www.tensorflow.org/versions/r2.14/api_docs/python/tf/Tensor) or [`tf.IndexedSlices`](https://www.tensorflow.org/versions/r2.14/api_docs/python/tf/IndexedSlices) objects, each with the same shape and type. [`tf.IndexedSlices`](https://www.tensorflow.org/versions/r2.14/api_docs/python/tf/IndexedSlices) objects will be converted into dense tensors prior to adding. |
| `name` | A name for the operation (optional). |

<br />

<br />

<br />

<br />

| ## Returns ||
|---|---|
| A [`tf.Tensor`](https://www.tensorflow.org/versions/r2.14/api_docs/python/tf/Tensor) of the same shape and type as the elements of `inputs`. ||

<br />

<br />

<br />

<br />

| ## Raises ||
|---|---|
| `ValueError` | If `inputs` don't all have same shape and dtype or the shape cannot be inferred. |

<br />