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

Nathaniel Smith njs at pobox.com
Tue Oct 23 13:24:28 EDT 2012

There's nothing like that built into numpy, no. I guess you could use
reduceat to calculate the total for each span of non-nans and then replace
each nan with the negative of that value so that plain cumsum would work,
but a loop is going to be easier (and a loop in Cython will be faster).

On 23 Oct 2012 18:11, "Cera, Tim" <tim at cerazone.net> wrote:

> I have an array that is peppered throughout in random spots with 'nan'.  I
> would like to use 'cumsum', but I want it to reset the accumulation to 0
> whenever a 'nan' is encountered.  Is there a way to do this?  Aside from a
> loop - which is what I am going to setup here in a moment.
> Kindest regards,
> Tim
> _______________________________________________
> NumPy-Discussion mailing list
> NumPy-Discussion at scipy.org
> http://mail.scipy.org/mailman/listinfo/numpy-discussion
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20121023/744c03c8/attachment.html>

More information about the NumPy-Discussion mailing list