[SciPy-user] accumulate with custom functions
mattknox_ca at hotmail.com
Sun Dec 24 10:17:30 CST 2006
I work quite a bit with another language called FAME, which is very vector based. In FAME I calculate exponentially weighted moving averages (exp mave) in the following way:
suppose X is a 1 dimensional array, then to Calculate an exp mave I would do:
myExpMave = X
Case firstvalue(X)+1 to lastvalue(X) #sets global operating range
set myExpMave[N] = myExpMave[N-1] + k * (myExpMave[N]-myExpMave[N-1]) #where k is some constant smoothing factor, N is an index placeholder recognized by FAME
essentially, what this does in numpy terms is accumulate with a function defined as "def mycalc(a, b, k): return a + k * (b - a)"
So, getting to the topic of my post, is their anyway to accomplish this kind of accumulation swiftly without resorting to writing a new ufunc in C? Or what would be the best way to do this kind of thing generally? Ie. accumulate with some kind of arbitrary, but still simple, function.
Thanks in advance for any help you can provide.
More information about the SciPy-user