Moving average with numpy

Memo to multiply moving average with numpy

Use convolve.

import numpy as np
import matplotlib.pyplot as plt


x=np.linspace(0,10,100)
yorg=np.sin(x)
y=np.sin(x)+np.random.randn(100)*0.2

num=5.0#Number of moving averages
b=np.ones(num)/num

y2=np.convolve(y, b, mode='same')#moving average

plt.plot(x,yorg,'r',label='Original sin')
plt.plot(x,y,'k-',label='Original series')
plt.plot(x,y2,'b--', label='moving average')
plt.legend()

result sin.png

Recommended Posts

Moving average with numpy
[Cistre] Buy and sell with moving average MACD ♬
Getting Started with Numpy
Learn with Cheminformatics NumPy
Matrix concatenation with Numpy
Hamming code with numpy
Regression analysis with NumPy
Extend NumPy with Rust
Kernel regression with Numpy only
I wrote GP with numpy
CNN implementation with just numpy
[Python] Calculation method with numpy
Try matrix operation with NumPy
Diffusion equation animation with NumPy
Debt repayment simulation with numpy
Implemented SMO with Python + NumPy
Stick strings together with Numpy
Handle numpy arrays with f2py
Use OpenBLAS with numpy, scipy
Python3 | Getting Started with numpy
Implementing logistic regression with NumPy
I tried to implement a volume moving average with Quantx
Display candlestick chart, volume, moving average, Bollinger band with mplfinance
Perform least squares fitting with numpy.
Digital twin with wheel moving robot
Moving object separation with Robust PCA
I tried moving food with SinGAN
Draw a beautiful circle with numpy
Implement Keras LSTM feedforward with numpy
Candlestick chart and moving average plot
Try moving 3 servos with Raspberry Pi
Extract multiple elements with Numpy array
Plot the Nikkei Stock Average with pandas
Read and write csv files with numpy
Create bins with NumPy, get data-bin correspondence
Graph trigonometric functions with numpy and matplotlib
I made a life game with Numpy
Speeding up numerical calculations with NumPy: Basics
Image processing with Python 100 knocks # 7 Average pooling
Read a character data file with numpy
Handle numpy with Cython (method by memoryview)
Use multithreaded BLAS / LAPACK with numpy / scipy
I compared the moving average of IIR filter type with pandas and scipy