[Numpy-discussion] Is there a way to reset an accumulate function?

Cera, Tim tim@cerazone....
Tue Oct 23 19:04:07 CDT 2012

> How about this hackish solution, for a quick non-looping fix?
> In [39]: a = np.array([1,2,3,4,np.nan,1,2,3,np.nan,3])
> idx = np.flatnonzero(np.isnan(a))
> a_ = a.copy()
> a_[idx] = 0
> np.add.reduceat(a_, np.hstack((0,idx)))
> Out[39]: array([ 10.,   6.,   3.])

Close, but not exactly what I need.  I want the 'cumsum', so given the 'a'
in your example:


I just made a loop, testing for 'nan'.  Not elegant, but it works so I am
not complaining.

Kindest regards,
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.scipy.org/pipermail/numpy-discussion/attachments/20121023/94cd3bdf/attachment.html 

More information about the NumPy-Discussion mailing list