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 :: median of array python 
Python :: python loop back to start 
Python :: write a file python 
Python :: with open as file python 
Python :: python 7zip extract 
Python :: auto slug field django 
Python :: how to create python file in powershell 
Python :: get requests python 
Python :: user defined functions python 
Python :: python loop opening file from directory 
Python :: create python list 
Python :: geopandas legend location 
Python :: python find file name 
Python :: pandas dataframe to series 
Python :: group multiple columns in pandas 
Python :: how to sort dict by value 
Python :: file manage py line 17 from exc django 
Python :: 3d array into 2d array python 
Python :: get last 3 in list python 
Python :: discord.py find voice channel by name 
Python :: smtplib send caleneder email 
Python :: python dataclass 
Python :: selenium element_to_be_clickable PYTHON 
Python :: How to Use Python all() Function to Check for Letters in a String using all function 
Python :: how append a directory based on current directory python 
Python :: planet 
Python :: python tkinter label 
Python :: add column to df from another df 
Python :: ffill dataframe python 
Python :: how to bold in colorama 
ADD CONTENT
Topic
Content
Source link
Name
9+1 =