title: Is there an equivalent of `sum()` builtin which uses augmented assignment?
body: <p>Is there any standard library/numpy equivalent of the following function:</p>
  
  <pre class="lang-py prettyprint-override"><code>def augmented_assignment_sum(iterable, start=0):
      for n in iterable:
          start += n
      return start
  </code></pre>
  
  <p>?</p>
  
  <p>While <code>sum(ITERABLE)</code> is very elegant, it uses <code>+</code> operator instead of <code>+=</code>, which in case of <code>np.ndarray</code> objects may affect performance.</p>
  
  <p>I have tested that my function may be as fast as <code>sum()</code> (while its equivalent using <code>+</code> is much slower).  As it is a pure Python function, I guess its performance is still handicapped, thus I am looking for some alternative:</p>
  
  <pre class="lang-py prettyprint-override"><code>In [49]: ARRAYS = [np.random.random((1000000)) for _ in range(100)]
  
  In [50]: def not_augmented_assignment_sum(iterable, start=0): 
      ...:     for n in iterable: 
      ...:         start = start + n 
      ...:     return start 
      ...:                                                                                                                                                                                                                                                                       
  
  In [51]: %timeit not_augmented_assignment_sum(ARRAYS)                                                                                                                                                                                                                          
  63.6 ms ± 8.88 ms per loop (mean ± std. dev. of 7 runs, 10 loops each)
  
  In [52]: %timeit sum(ARRAYS)                                                                                                                                                                                                                                                   
  31.2 ms ± 2.18 ms per loop (mean ± std. dev. of 7 runs, 10 loops each)
  
  In [53]: %timeit augmented_assignment_sum(ARRAYS)                                                                                                                                                                                                                              
  31.2 ms ± 4.73 ms per loop (mean ± std. dev. of 7 runs, 10 loops each)
  
  In [54]: %timeit not_augmented_assignment_sum(ARRAYS)                                                                                                                                                                                                                          
  62.5 ms ± 12.1 ms per loop (mean ± std. dev. of 7 runs, 10 loops each)
  
  In [55]: %timeit sum(ARRAYS)                                                                                                                                                                                                                                                   
  37 ms ± 9.51 ms per loop (mean ± std. dev. of 7 runs, 10 loops each)
  
  In [56]: %timeit augmented_assignment_sum(ARRAYS)                                                                                                                                                                                                                              
  27.7 ms ± 2.53 ms per loop (mean ± std. dev. of 7 runs, 10 loops each)
  
  </code></pre>
  
  <p>I have tried to use <code>functools.reduce</code> combined with <code>operator.iadd</code>, but its performace is similar:</p>
  
  <pre><code>In [79]: %timeit reduce(iadd, ARRAYS, 0)                                                                                                                                                                                                                                       
  33.4 ms ± 11.6 ms per loop (mean ± std. dev. of 7 runs, 10 loops each)
  
  In [80]: %timeit reduce(iadd, ARRAYS, 0)                                                                                                                                                                                                                                       
  29.4 ms ± 2.31 ms per loop (mean ± std. dev. of 7 runs, 10 loops each)
  
  </code></pre>
  
  <p>I am also interested in memory efficiency, thus prefer augmented assignments as they not require creation of intermediate objects.</p>