Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

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])
Comment

numpy moving average

import numpy as np

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

PREVIOUS NEXT
Code Example
Python :: multiple loss pytorch 
Python :: dynamo scripts template 
Python :: python make a shop menu 
Python :: how to get more than one word in a list in python 
Python :: decyphing vigener cypher without key 
Python :: python function to check list element ratio with total data 
Python :: truncate date to midnight in pandas column 
Python :: Ascending discending 
Python :: python collections counter 
Python :: sort list of files by name python 
Python :: pandas find median of non zero values in a column 
Python :: string list into list pandas 
Python :: python extraer primer elemento lista 
Python :: python interpreter clear screen 
Python :: pandas percentage change across 3 periods 
Python :: qlineedit autocomplete python 
Python :: numpy multiply by inverse square root of value 
Python :: find python path windows 
Python :: YouCompleteMe unavailable: requires Vim compiled with Python (3.6.0+) support. 
Python :: lambda with two columns pandas 
Python :: pyspark correlation between multiple columns 
Python :: how to loop over day name in python 
Python :: selenium python download mac 
Python :: tqdm remove progress bar when done 
Python :: dataframe index rename 
Python :: how to cycle through panes in tmux 
Python :: list to tensor 
Python :: How to convert a string to a dataframe in Python 
Python :: how to add column headers in pandas 
Python :: hot to pay music in pygame 
ADD CONTENT
Topic
Content
Source link
Name
3+5 =