Cumulative Sum List
<p>I'm trying to create a cumulative list, but my output clearly isn't cumulative. Does anyone know what I'm doing wrong?
Thanks</p>

<pre><code>import numpy as np
import math
import random

l=[]
for i in range (50):
    def nextTime(rateParameter):
        return -math.log(1.0 - random.random()) / rateParameter
    a = np.round(nextTime(1/15),0)
    l.append(a)
np.cumsum(l)
print(l)
</code></pre>

<p>The cumulative sum is not taken <em>in place</em>, you have to assign the return value:</p>

<pre><code>cum_l = np.cumsum(l)
print(cum_l)
</code></pre>

<p>You don't need to place that function in the <code>for</code> loop. Putting it outside will avoid defining a new function at every iteration and your code will still produce the expected result.</p>

python numpy cumsum