[Numpy-discussion] reverse cumsum?

Ken Basye kbasye1@jhu....
Tue Jul 6 08:56:35 CDT 2010


Hi,
   Is there a simple way to get a cumsum in reverse order?  So far, the 
best I've come up with is to use fancy indexing twice to reverse things:

 >>> x = np.arange(10)
 >>> np.cumsum(x[np.arange(9, -1, -1)])[np.arange(9, -1, -1)]
array([45, 45, 44, 42, 39, 35, 30, 24, 17,  9])

If it matters, I only care about the 1-d case at this point.

  Thanks,
      Ken



More information about the NumPy-Discussion mailing list