我复制了以下几行

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
感谢您的帮助。
亲切的问候。
伊沃

最佳答案

>>>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%,而是您可以在其中找到的大多数重要的重要商品。

关于python - 为什么会出现此错误? AttributeError:“模块”对象没有属性“周期图”,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/18392045/

10-14 04:51