推荐学习书目
› Learn Python the Hard Way
Python Sites
› PyPI - Python Package Index
› http://diveintopython.org/toc/index.html
› Pocoo
值得关注的项目
› PyPy
› Celery
› Jinja2
› Read the Docs
› gevent
› pyenv
› virtualenv
› Stackless Python
› Beautiful Soup
› 结巴中文分词
› Green Unicorn
› Sentry
› Shovel
› Pyflakes
› pytest
Python 编程
› pep8 Checker
Styles
› PEP 8
› Google Python Style Guide
› Code Style from The Hitchhiker's Guide
songdg
V2EX  ›  Python

求解析一下这个函数的原理

  •  1
     
  •   songdg · Oct 16, 2018 · 2471 views
    This topic created in 2908 days ago, the information mentioned may be changed or developed.
    在 stackoverflow 里找到一个 numpy 版指数移动平均的函数,但实在看不懂,还有当 window 少于等于 7 时不能得到正确的结果。
    def numpy_ewma_vectorized_v2(data, window):
    alpha = 2 /(window + 1.0)
    alpha_rev = 1-alpha
    n = data.shape[0]
    pows = alpha_rev**(np.arange(n+1))
    scale_arr = 1/pows[:-1]
    offset = data[0]*pows[1:]
    pw0 = alpha*alpha_rev**(n-1)
    mult = data*pw0*scale_arr
    cumsums = mult.cumsum()
    out = offset + cumsums*scale_arr[::-1]
    return out
    3 replies  •  2018-10-16 10:48:40 +08:00
    yuankui
        1
    yuankui  
       Oct 16, 2018
    代码这么乱, 没有看下去的欲望。。
    Justin13
        2
    Justin13  
       Oct 16, 2018 via Android
    类似这种问题,应该先看数学原理。而不是上来看代码,看到懵逼。
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   933 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 33ms · UTC 19:01 · PVG 03:01 · LAX 12:01 · JFK 15:01
    ♥ Do have faith in what you're doing.