Spec-Zone.ru › TensorFlow

tf.math.add_n

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

View aliases

Main aliases

tf.add_n

Compat aliases for migration

See Migration guide for more details.

tf.compat.v1.add_n, tf.compat.v1.math.add_n

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

Used in the notebooks

Used in the guide Used in the tutorials
  • Validating correctness & numerical equivalence
  • Use TF1.x models in TF2 workflows
  • Effective Tensorflow 2
  • Distributed training with TensorFlow
  • Use a GPU
  • Neural style transfer
  • Custom training with tf.distribute.Strategy
  • Custom training loop with Keras and MultiWorkerMirroredStrategy
  • Parameter server training with ParameterServerStrategy
  • Overfit and underfit

All inputs in the list must have the same shape. 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]).numpy()
array([[ 7, 16],
       [10, 25]], dtype=int32)

See Also:

  • tf.reduce_sum(inputs, axis=0) - This performs the same mathematical operation, but tf.add_n may be more efficient because it sums the tensors directly. reduce_sum on the other hand calls tf.convert_to_tensor on the list of tensors, unnecessarily stacking them into a single tensor before summing.
Args
inputs A list of tf.Tensor or tf.IndexedSlices objects, each with the same shape and type. tf.IndexedSlices objects will be converted into dense tensors prior to adding.
name A name for the operation (optional).
Returns
A tf.Tensor of the 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.

© 2022 The TensorFlow Authors. All rights reserved.
Licensed under the Creative Commons Attribution License 4.0.
Code samples licensed under the Apache 2.0 License.
https://www.tensorflow.org/api_docs/python/tf/math/add_n

Spec-Zone.ru

Настройки Оффлайн Что нового Помощь О нас
Spec-Zone .ru
спецификации, руководства, описания, API