我正在尝试对列表进行逆傅里叶变换,由于某种原因,我不断收到以下错误
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "simulating_coherent_data.py", line 238, in <module>
exec('ift%s = np.fft.ifft(nd.array(FTxSQRT_PS%s))'(x,x))
TypeError: 'str' object is not callable
我无法弄清楚我的字符串在哪里。我所涉及的代码部分如下
def FTxSQRT_PS(FT,PS):
# Import: The Fourier Transform and the Power Spectrum, both as lists
# Export: The result of FTxsqrt(PS), as a list
# Function:
# Takes each element in the FT and PS and finds FTxsqrt(PS) for each
# appends each results to a list called signal
signal = []
print type(PS)
for x in range(len(FT)):
indiv_signal = np.abs(FT[x])*math.sqrt(PS[x])
signal.append(indiv_signal)
return signal
for x in range(1,number_timesteps+1):
exec('FTxSQRT_PS%s = FTxSQRT_PS(fshift%s,power_spectrum%s)'%(x,x,x))
exec('ift%s = np.fft.ifft(FTxSQRT_PS%s)'(x,x))
FTxSQRT_PS%s都是列表。 fshift%s是np.array,power_spectrum%s是一个列表。我也尝试将FTxSQRT_PS%s的类型设置为np.array,但这没有帮助。 我有几行非常相似的代码可以正常工作;
for x in range(1,number_timesteps+1):
exec('fft%s = np.fft.fft(source%s)'%(x,x))
其中,源%s的类型均为np.array
我唯一能想到的是,np.fft.ifft可能不是我应该如何为Python 2.7.6进行逆傅里叶变换,但我也找不到替代方案。
如果您想查看整个代码,请告诉我,我遇到麻烦的地方大概有240行,但很多都是评论。
感谢您的帮助,
特雷莎
答案 0 :(得分:1)
您错过了%
exec('ift%s = np.fft.ifft(FTxSQRT_PS%s)'(x,x))
应该是:
exec('ift%s = np.fft.ifft(FTxSQRT_PS%s)'%(x,x))