tf.math.add_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.add_n(
    inputs, name=None
)
Used in the notebooks
  
    
      | Used in the guide | Used in the tutorials | 
  
  
    
      |  |  | 
  
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_nmay be more efficient because it sums the
tensors directly.- reduce_sumon the other hand calls- tf.convert_to_tensoron the list of tensors, unnecessarily stacking them
into a single tensor before summing.
| Args | 
|---|
| inputs | A list of tf.Tensorortf.IndexedSlicesobjects, each with the
same shape and type.tf.IndexedSlicesobjects will be converted into
dense tensors prior to adding. | 
| name | A name for the operation (optional). | 
| Returns | 
|---|
| A tf.Tensorof the same shape and type as the elements ofinputs. | 
| Raises | 
|---|
| ValueError | If inputsdon'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. Some content is licensed under the numpy license.
  Last updated 2024-04-26 UTC.
  
  
  
    
      [null,null,["Last updated 2024-04-26 UTC."],[],[]]