• 数据平滑处理


    简单移动平均线

    简单移动平均线是计算与等权重的指示函数的卷积,也可以不等权重. 
    1.用ones函数创建一个元素均为1的数组,然后对整个数组除以N,得到等权重. 
    2.使用权值,调用convolve函数. 
    3.从convolve函数分安徽的数组中取出中间的长度为N的部分(即两者作卷积运算时完全重叠的区域.) 
    4.使用matplotlib绘图

    import numpy as np
    import matplotlib.pyplot as plt
    import sys
    
    N=int(sys.argv[1])
    weights=np.ones(N)/N
    print("WEIGHTS",weights)
    
    c=np.loadtxt('/home/syd/Documents/stockdata.csv',delimiter=',',
    skiprows=(2),usecols=(2,),unpack=True)
    sam=np.convolve(weights,c)[N-1:-N+1]
    t=np.arange(N-1,len(c))
    
    plt.plot(t,c[N-1:],lw=1.0)
    plt.plot(t,sam,lw=2.0)
    plt.show()

    这里写图片描述

    窗函数:hanning汉宁窗

    汉宁窗是一个加权余弦窗函数.numpy.hanning(M) Return the Hanning window.

    Parameters: M : int 
    Number of points in the output window. If zero or 
    Returns: out : ndarray, shape(M,) 
    The window, with the maximum value normalized to one (the value one 
    appears only if M is odd).

    1.调用hanning函数计算权重,生成一个长度为N的窗口,输入参数N

    N=int(sys.argv[1])
    weights=np.hanning(N)
    print(weights)

    2.使用convolve,进行卷积运算.然后绘图.

    import numpy as np
    import matplotlib.pyplot as plt
    import sys
    
    N=int(sys.argv[1])
    weights=np.hanning(N)
    print("WEIGHTS",weights)
    
    c=np.loadtxt('/home/syd/Documents/stockdata.csv',delimiter=',',
    skiprows=(2),usecols=(2,),unpack=True)
    sam=np.convolve(weights/weights.sum(),c)[N-1:-N+1]
    t=np.arange(N-1,len(c))
    
    plt.plot(t,c[N-1:],lw=1.0)
    plt.plot(t,sam,lw=2.0)
    plt.show()

    这里写图片描述

    作者:轻笑再轻叹 出处链接:https://blog.csdn.net/a1212125/article/details/78030640
  • 相关阅读:
    storage存储对象和数组类型时候的问题
    关于vue-router路径配置的问题
    解决v-for产生的警告的办法
    网页调用打印机打印文件
    vue-router的link样式设置问题
    在vue项目当中使用sass
    使用正则获取地址栏参数的方法
    escape、encodeURI和encodeURIComponent的区别
    SQLServer安装错误之--->无法打开项 UNKNOWNComponentsDA42BC89BF25F5BD0AF18C3B9B1A1EE8c1c4f01781cc94c4c8fb1542c0981a2a
    软件收集网站!
  • 原文地址:https://www.cnblogs.com/jingsupo/p/9109695.html
Copyright © 2020-2023  润新知