[Numpy-discussion] Is there a way to reset an accumulate function?
Cera, Tim
tim at cerazone.net
Tue Oct 23 20:04:07 EDT 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:
array([1,2,6,10,0,1,3,6,0,3])
I just made a loop, testing for 'nan'. Not elegant, but it works so I am
not complaining.
Kindest regards,
Tim
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20121023/94cd3bdf/attachment.html>
More information about the NumPy-Discussion
mailing list