[Numpy-discussion] computing some running sums

Keith Goodman kwgoodman at gmail.com
Tue Jun 1 11:02:15 EDT 2010


On Tue, Jun 1, 2010 at 6:56 AM, Keith Goodman <kwgoodman at gmail.com> wrote:
> On Tue, Jun 1, 2010 at 6:47 AM, Neal Becker <ndbecker2 at gmail.com> wrote:
>> Not sure what to call this.
>>
>> Any suggestion on computing the vector:
>>
>> sum(u[i*M:i*M+N]) for i in range (len(u)/M)
>
> How about a cumsum and then a loop to take the differences of the
> desired indices of the cumsum? Might be faster to convert the cumsum
> to a list (looks like you are interested in 1d?) for use in the loop.
> Converting the loop to cython would be the next step.

c = cumsum
c.take(idx_left, axis=0) - c.take(idx_right, axis=0)



More information about the NumPy-Discussion mailing list