2013-08-22 26 views
0

我从** http://docs.scipy.org/doc/scipy/reference/generated/scipy.signal.periodogram.html#scipy.signal.periodogram复制以下行为什么我会发生这个错误? AttributeError的:“模块”对象有没有属性“周期图”

from scipy import signal 
import matplotlib.pyplot as plt 
import numpy as np 

fs = 10e3 
N = 1e5 
amp = 2*np.sqrt(2) 
freq = 1234.0 
noise_power = 0.001 * fs/2 
time = np.arange(N)/fs 
x = amp*np.sin(2*np.pi*freq*time) 
x += np.random.normal(scale=np.sqrt(noise_power), size=time.shape) 
# Compute and plot the power spectral density. 

f, Pxx_den = signal.periodogram(x, fs) 
plt.semilogy(f, Pxx_den) 
plt.xlabel('frequency [Hz]') 
plt.ylabel('PSD [V**2/Hz]') 
plt.show() 

但是当我尝试运行我得到这个错误代码:

f, Pxx_den = signal.periodogram(x, fs) 
AttributeError: 'module' object has no attribute 'periodogram' 

我在使用Scipy版本0.12 感谢您的帮助。 亲切的问候。 伊沃

+0

在解释器类型'from scipy import signal'中,然后输入'dir(signal)',你会在该列表中看到'periodogram'吗? – TehTris

+0

如果你打印信号,你会得到什么? – user2357112

+0

当我打印目录(信号)时,我得到了很多方法,但没有周期图。如果我从scipy导入信号更改为scipy.signal导入谱,我将得到lombscargle方法。这个方法是从scipy v0.12中删除的吗?或者在另一个模块中?亲切的问候.Ivo – TMoover

回答

1
>>>from scipy import signal 

>>>print [x for x in dir(signal) if x == 'periodogram'] #just list comprehension to limit the amount of methods displayed 
['periodogram'] 

你肯定有什么不对您SciPy的安装。我推荐http://www.lfd.uci.edu/~gohlke/pythonlibs/#scipy这个网站通常是我安装或导入模块时遇到困难的第一个地方,您认为这些模块安装正确。

网站上的东西不是100%,而是大部分重要的东西,你可以在那里找到。

相关问题