LoginSignup
42
43

More than 3 years have passed since last update.

numpyで移動平均

Last updated at Posted at 2017-04-16

numpyで移動平均をかけるメモ

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 #移動平均の個数
b=np.ones(num)/num

y2=np.convolve(y, b, mode='same')#移動平均

plt.plot(x,yorg,'r',label='オリジナルsin')
plt.plot(x,y,'k-',label='元系列')
plt.plot(x,y2,'b--', label='移動平均')
plt.legend()

結果
sin.png

42
43
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
42
43