time series calculation in list comprehension?
Paul Rubin
http
Fri Mar 10 13:55:41 EST 2006
"falcon" <shahbazc at gmail.com> writes:
> Is there a way I can do time series calculation, such as a moving
> average in list comprehension syntax? I'm new to python but it looks
> like list comprehension's 'head' can only work at a value at a time. I
> also tried using the reduce function and passed in my list and another
> function which calculates a moving average outside the list comp. ...
> but I'm not clear how to do it. Any ideas? Thanks.
Do you mean something like this?
for i in xrange(5, len(ts)):
# compute and print moving average from i-5 to i
print i, sum(ts[i-5:i]) / 5.
More information about the Python-list
mailing list