Moving average or running mean

后端 未结 27 1339
庸人自扰
庸人自扰 2020-11-22 08:37

Is there a SciPy function or NumPy function or module for Python that calculates the running mean of a 1D array given a specific window?

27条回答
  •  一个人的身影
    2020-11-22 09:17

    For a ready-to-use solution, see https://scipy-cookbook.readthedocs.io/items/SignalSmooth.html. It provides running average with the flat window type. Note that this is a bit more sophisticated than the simple do-it-yourself convolve-method, since it tries to handle the problems at the beginning and the end of the data by reflecting it (which may or may not work in your case...).

    To start with, you could try:

    a = np.random.random(100)
    plt.plot(a)
    b = smooth(a, window='flat')
    plt.plot(b)
    

提交回复
热议问题