How to find moving average from data points in Python

The moving average of data points is a series of averages of subsets of the entire data set.

Solution for How to find moving average from data points in Python : You can use numpy.cumsum() to find moving average from data points Use numpy.cumsum(data) where data is the Numpy array to take the cumulative sum of. To find the sum of n consecutive elements insert a 0 at the beginning of the data with numpy.insert(data, 0, 0). Then, use cumsum_vector[n:] – cumsum_vector[:-n] to remove elements not included in the desired subset of length n from the sums. Divide this vector by n to obtain the moving average.


how-to-find-moving-average-from-data-points-in-python