为什么我收到此错误? AttributeError:'module'对象没有属性'periodogram'

时间:2013-08-22 22:50:37

标签: python scipy

我复制了以下几行

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()

来自** http://docs.scipy.org/doc/scipy/reference/generated/scipy.signal.periodogram.html#scipy.signal.periodogram,但当我尝试运行代码时,我收到此错误:

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

我正在使用Scipy版本0.12 谢谢你的帮助。 亲切的问候。 IVO

1 个答案:

答案 0 :(得分:2)

>>>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%的内容,而是您可以在那里找到的大部分重要内容。