[SciPy-user] moving average, moving standard deviation, etc...

Gael Varoquaux gael.varoquaux at normalesup.org
Sat Dec 23 12:51:05 CST 2006


For all linear operations a convolution will do the trick.

For non-linear operations, such as the standard deviation an ugly but
efficient way of doing it would be:

sqrt(A[0:-10]**2 + A[1;-9]**2 + ... )

Maybe there is a more beautiful way of writing this.


On Sat, Dec 23, 2006 at 01:42:39PM -0500, Matt Knox wrote:

> Does anyone know of a slick way to calculate a simple moving average and/or moving standard deviation? And when I say slick, I mean loop-free way, because it would be fairly easy to code a looping way of doing it, it would just be really slow.

> To be more specific, when I say moving standard deviation, I mean for example...

> if A is a 1-dimensional array with 100 elements, and I'm using a window size of 10, then the result at index 10 would be A[0:10].std(), the result at index 11 would be A[1:11].std() , etc...  

> And similarly for moving average, and so forth. Is their a general way to do these kind of things? Or would it have to be a special case for each type of calculation to avoid looping?

> Any help is greatly appreciated. Thanks in advance,

> - Matt

> _______________________________________________
> SciPy-user mailing list
> SciPy-user at scipy.org
> http://projects.scipy.org/mailman/listinfo/scipy-user

More information about the SciPy-user mailing list