← 返回题库
初级

移动平均

未完成
初级参考 完整示例代码供参考,建议自己理解后重新输入
def solve():
    import numpy as np
    import matplotlib.pyplot as plt
    np.random.seed(42)
    n = 200
    time = np.arange(n)
    ts = 0.05 * time + 10 * np.sin(2 * np.pi * time / 50) + np.random.normal(0, 3, n)
    window = 10
    ma = np.convolve(ts, np.ones(window)/window, mode='valid')
    plt.figure(figsize=(12, 6))
    plt.plot(time, ts, 'b-', alpha=0.5, label='原始数据')
    plt.plot(time[window-1:], ma, 'r-', linewidth=2, label=f'{window}期移动平均')
    plt.xlabel('时间')
    plt.ylabel('值')
    plt.title('移动平均平滑')
    plt.legend()
    plt.grid(alpha=0.3)
    plt.show()
Python 代码 🔒 登录后使用
🔒

登录后即可练习

注册免费账号,在浏览器中直接运行 Python 代码