Dan*_*ein 1 python numpy scipy
我的数据由一系列时间组成,每秒有10个数据点,每个时间对应一个强度值数组.所以,举一个例子,让我说我有:
times = np.arange(0,100,0.1)
intensities = np.random.rand(len(times))
Run Code Online (Sandbox Code Playgroud)
我想看看如果我使用更长的平均时间,数据会是什么样子,所以我想创建一些箱子,例如1秒,5秒和10秒,并平均这些新箱子中的强度值.numpy中最好的方法是什么?(或者其他python包,但我假设numpy/scipy对我有用.)我可以使用for循环,但我希望有更好的方法.谢谢!
你可以计算移动平均使用convolve的计算器提到这里.
from pylab import plot, show
import numpy as np
times = np.arange(0,100,0.1)
intensities = np.random.rand(len(times))
def window(size):
return np.ones(size)/float(size)
plot(times,intensities,'k.')
plot(times,np.convolve(intensities,window(10),'same'),'r')
plot(times,np.convolve(intensities,window(100),'same'),'b')
show()
Run Code Online (Sandbox Code Playgroud)

| 归档时间: |
|
| 查看次数: |
4450 次 |
| 最近记录: |