Python 为什么我会犯这个错误?属性错误:';模块';对象没有属性';周期图';

Python 为什么我会犯这个错误?属性错误:';模块';对象没有属性';周期图';,python,scipy,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(sca

我复制了以下几行

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

您的scipy安装肯定有问题。我建议这个网站通常是我在安装或导入你认为正确安装的模块时遇到困难的第一个地方


网站上的内容列表不是所有内容的100%,而是大部分重要的内容。

在解释器中键入scipy导入信号中的
,然后键入
dir(signal)
,你在列表中看到“周期图”了吗?如果打印信号,你会得到什么?当我打印dir(signal)时我有很多方法,但没有周期图。如果我从scipy导入信号更改为scipy.signal导入光谱,我将得到lombscargle方法。该方法是否已从scipy v0.12中删除?还是在另一个模块中?亲切的问候。Ivother API声明它应该在.12中出现。。。。。因此,您可能遇到了某种安装问题。我从来没有使用过scipy,所以我不确定它是否像传统的python模块一样安装,但也许可以检查一下站点包/scipy/signal?是的,肯定是安装问题。我的dir(信号)中肯定有周期图(我刚刚安装)
>>>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']