我需要形成一个新的数字序列,方法是替换每个数据值,从第4个条目开始,从最后一个条目的第4个条目结束,并使用以下公式对它周围的七个点进行加权平均: / p>
(y[i-3] + 2y[i-2] + 3y[i-1] + 3y[i] + 3y[i+1] + 2y[i+2] + y[i+3]) // 15
(注意。i-或i +一些数字是下标,以防不明显。)
这里是产生原始图形的代码,但是我需要使用上述公式对新图形进行平滑处理。数据文件产生一个整数数组,设置为[-24,4,-4,-12,-52...]
。我什至不知道从哪里开始该公式会有所帮助。
from matplotlib import pyplot as plt
with open('2_Record2308.dat','r') as f:
data = [int(x) for x in f]
graph = data
fig,ax = plt.subplots()
ax.plot(graph)
ax.legend()
ax.set_ylabel('Raw')
plt.tight_layout()
plt.show()