scipy 中的 fftshift 是否损坏?

发布于 2024-09-14 02:27:45 字数 810 浏览 2 评论 0原文

我使用最新版本的 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  

编辑:我发现了问题。我的 python 解释器是通过 -Qnew 选项隐式调用的(通过我的编辑器设置)。这显然破坏了 scipy 代码。 感谢所有回复的人!

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!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

↘人皮目录ツ 2024-09-21 02:27:45

您应该在 http://www.scipy.org/BugReport 上填写错误报告

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

秋叶绚丽 2024-09-21 02:27:45

与我的设置配合良好,如果当前版本中存在错误,请尝试安装旧版本并填写报告。

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

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'
>>>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文