[Numpy-discussion] reverse cumsum?

Alan G Isaac aisaac at american.edu
Tue Jul 6 18:23:50 EDT 2010


On 7/6/2010 3:37 PM, Joshua Holbrook wrote:
> In [10]: np.array(list(reversed(np.arange(10).cumsum())))
> Out[10]: array([45, 36, 28, 21, 15, 10,  6,  3,  1,  0])
>


That might appear to match the subject line
but does not match the OP's example output,
which was [45, 45, 44, 42, 39, 35, 30, 24, 17,  9].

You are giving the equivalent of x.cumsum()[::-1],
while the OP asked for the equivalent of x[::-1].cumsum()[::-1].

fwiw,
Alan Isaac



More information about the NumPy-Discussion mailing list