Re: best cumulative sum
- From: "David Isaac" <aisaac0@xxxxxxxxxxx>
- Date: Mon, 21 Nov 2005 19:52:12 GMT
> Alan Isaac wrote:
>> Like SciPy's cumsum.
"Colin J. Williams" <cjw@xxxxxxxxxxxx> wrote in message
news:rvngf.2987$gK4.200074@xxxxxxxxxxxxxxxxxxxxxxxx
> Doesn't numarray handle this?
Sure.
One might say that numarray is in the process of becoming scipy.
But I was looking for a solution when these are available.
Something like:
def cumreduce(func, seq, init = None):
"""Return list of cumulative reductions.
Example use:
>>> cumreduce(operator.mul, range(1,5),init=1)
[1, 2, 6, 24]
>>>
:author: Alan Isaac
:license: public domain
"""
if not seq:
cr = [init]*bool(init)
else:
cr = [seq[0]] * len(seq)
if init:
cr[0] = func(cr[0],init)
for idx in range(1,len(seq)):
cr[idx] = func(cr[idx-1],seq[idx])
return cr
.
- Follow-Ups:
- Re: best cumulative sum
- From: Michael Spencer
- Re: best cumulative sum
- From: David Isaac
- Re: best cumulative sum
- References:
- best cumulative sum
- From: David Isaac
- Re: best cumulative sum
- From: Micah Elliott
- Re: best cumulative sum
- From: Erik Max Francis
- Re: best cumulative sum
- From: bonono@xxxxxxxxx
- Re: best cumulative sum
- From: David Isaac
- Re: best cumulative sum
- From: Colin J. Williams
- best cumulative sum
- Prev by Date: Re: ignore specific data
- Next by Date: Re: Why are there no ordered dictionaries?
- Previous by thread: Re: best cumulative sum
- Next by thread: Re: best cumulative sum
- Index(es):