[Numpy-discussion] Want cumsum-like function

Peter Shinners pete@shinners....
Wed Feb 24 22:53:50 CST 2010


I want a function that works like cumsum, but starts at zero, instead of 
starting with the first actual value.

For example; I have an array with [4,3,3,1].
Cumsum will give me an array with [4,7,10,11].
I want an array that is like [0,4,7,8].

It looks like I could indirectly do this:

tallies = np.cumsum(initial_array)
np.subtract(tallies, tallies[0], tallies)

But is there a more efficient way to get this specific result?



More information about the NumPy-Discussion mailing list