所以我有股票市场数据(日期从0开始,&一个收盘价),并用这个我用numpy.fft来计算快速傅里叶变换和相应的频率,然后得到这些以压缩列表的形式,'FFT,频率'。垂直bin中的y值的均值
logbins = np.logspace(Min(logX),max(logX),numbins=10, base=10.0
我那么数字化的频率值到这些箱和使用:
for k in range(1,len(freqlogbins)):
mean_freq.append(np.mean(Tfreq2[freqdig==k]))
的正常工作,但是我也需要以某种方式制定出我已经频率值使用分成垂直数箱每个bin中的值的平均值为y
。
我想这是某种可以参照的ZippedList[0,i]
的x
值和y
值ZippedList[1,i]
,但不能完全解决如何。
下面是可复制的代码的示例:
import numpy as np
T_date0=np.arange(0,400)
T_price=np.random.uniform(100,400, size=400)
T_fft=np.fft.fft(T_price)
Tfreq=np.fft.fftfreq(T_date0.shape[-1])
我然后使用消除任何负频率值和相应的FFT值:
Tfreq2=[]
T_fft2=[]
for i in range(len(Tfreq)):
if Tfreq[i]>0:
Tfreq2.append(Tfreq[i])
T_fft2.append(T_fft[i])
T_fft_absSq=(np.absolute(T_fft2))**2
logTFAS=np.log10(T_fft_absSq)
logTfreq=np.log10(Tfreq2)
numbins=10
logbins=np.logspace((min(logTfreq)-0.00000001),(max(logTfreq)+0.00000001),num=numbins, base=10.0) #The +/-0.00000001 are so that the endpoints lie in the bin intervals.
Tfreq2=np.array(Tfreq2)
TFAS=np.array(T_fft_absSq)
freqdig=np.digitize(Tfreq2,logbins)
mean_freq=[]
mean_fft=[]
for k in range(1,len(logbins)):
mean_freq.append(np.mean(Tfreq2[freqdig==k]))
Fourier=zip(logTfreq,logTFAS)
##This is where I need to work out the mean of the y values, in the vertical bins
下面是数据的模样,其中,所述黑色虚线表示垃圾箱,黄色虚线表示每个垃圾箱中x值的平均值。蓝线是二阶多项式拟合。
显然,随机数据看起来有点不同于我在下面发布的链接,但它提供了一个想法。
你能写下一个复制粘贴可运行的例子,填充所有的变量(假/随机数据是好的),并导入你正在使用的模块?例如,我们不知道'Tfreq2'和'freqdig'是什么。 – YXD 2014-12-02 14:48:56
欢呼声,编辑了一个更清晰的描述 – 2014-12-02 18:27:23