我使用的是numpy / scipy的最新版本 以下脚本不起作用:
import numpy as np
import matplotlib.pyplot as plt
from scipy.fftpack import fft, fftshift, fftfreq
hn= np.ones(10)
hF = fft(hn,1024)
shifted = fftshift(hF)
它给出以下错误消息:
Traceback (most recent call last):
File "D:\deleteme\New3.py", line 6, in <module>
shifted = fftshift(hF)
File "C:\Python26\lib\site-packages\numpy\fft\helper.py", line 40, in fftshift
y = take(y,mylist,k)
File "C:\Python26\lib\site-packages\numpy\core\fromnumeric.py", line 103, in take
return take(indices, axis, out, mode)
TypeError: array cannot be safely cast to required type
编辑:我发现了问题。我使用-Qnew选项隐式调用了我的python解释器(通过我的编辑器设置)。这显然打破了scipy代码。 感谢所有回复的人!
答案 0 :(得分:1)
答案 1 :(得分:0)
使用我的设置正常工作,如果它是当前版本中的错误,请尝试安装较旧的副本并填写报告。
>>> import numpy as np
>>> import matplotlib.pyplot as plt
>>> from scipy.fftpack import fft, fftshift, fftfreq
>>> hn= np.ones(10)
>>> hF = fft(hn,1024)
>>> shifted = fftshift(hF)
>>> shifted
array([ 0.00000000+0.j , 0.00084688+0.03066325j,
0.00338468+0.06122841j, ..., 0.00760489-0.09159769j,
0.00338468-0.06122841j, 0.00084688-0.03066325j])
>>> import sys
>>> sys.version
'2.6.4 (r264:75706, Jan 22 2010, 16:41:54) [MSC v.1500 32 bit (Intel)]'
>>> import numpy
>>> numpy.version.version
'1.3.0'
>>> import scipy
>>> scipy.version.version
'0.7.1'
>>> import matplotlib
>>> matplotlib.__version__
'0.99.1'
>>>