Horje
numpy rolling average Code Example
moving average numpy
def moving_average(a, n=3) :
    ret = np.cumsum(a, dtype=float)
    ret[n:] = ret[n:] - ret[:-n]
    return ret[n - 1:] / n

>>> a = np.arange(20)
>>> moving_average(a)
array([  1.,   2.,   3.,   4.,   5.,   6.,   7.,   8.,   9.,  10.,  11.,
        12.,  13.,  14.,  15.,  16.,  17.,  18.])
>>> moving_average(a, n=4)
array([  1.5,   2.5,   3.5,   4.5,   5.5,   6.5,   7.5,   8.5,   9.5,
        10.5,  11.5,  12.5,  13.5,  14.5,  15.5,  16.5,  17.5])
numpy rolling average
import numpy as np

def moving_average(x, w):
    return np.convolve(x, np.ones(w), 'valid') / w




Python

Related
Deleting a file using python Code Example Deleting a file using python Code Example
numpy moving average Code Example numpy moving average Code Example
convert np shape (a,) to (a,1) Code Example convert np shape (a,) to (a,1) Code Example
Creating new virtual environment in python Code Example Creating new virtual environment in python Code Example
basic flask app python Code Example basic flask app python Code Example

Type:
Code Example
Category:
Coding
Sub Category:
Code Example
Uploaded by:
Admin
Views:
7