# credit to the Stack Overflow user in the source link # x is the numpy (np) array you want to moving-average # w is the actual length of the window of the moving average (an integer) np.convolve(x, np.ones(w), 'valid') / w