views:

67

answers:

2

I use the latest version of numpy/scipy.
The following script does not work:

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)  

It gives the following error message:

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  

EDIT: i have found the problem. My python interpreter was implicitly called (via my editor settings) with the -Qnew option. This apparently breaks scipy code. Thanks to all who responded!

A: 

You should fill in a bug report on http://www.scipy.org/BugReport

cmdev
A: 

Works fine with my setup, if it's a bug in the current version try installing an older copy and filling out a report.

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