2010-08-13 75 views
0

我使用最新版本的numpy/scipy。
下面的腳本不工作:在scipy中是fftshift破碎?

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 

編輯:我已經發現了這個問題。我的python解釋器被隱式調用(通過我的編輯器設置)和-Qnew選項。這顯然打破了scipy代碼。 感謝所有回覆!

+0

適合我。你確定代碼是正確的嗎? – katrielalex 2010-08-13 14:23:41

+0

也適合我。我正在使用最新版本的Numpy(1.5.0b1)和Scipy(0.8.0rc3)。 – 2010-08-13 16:16:32

回答

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' 
>>>