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 感谢您的帮助。 亲切的问候。 伊沃
在解释器类型'from scipy import signal'中,然后输入'dir(signal)',你会在该列表中看到'periodogram'吗? – TehTris
如果你打印信号,你会得到什么? – user2357112
当我打印目录(信号)时,我得到了很多方法,但没有周期图。如果我从scipy导入信号更改为scipy.signal导入谱,我将得到lombscargle方法。这个方法是从scipy v0.12中删除的吗?或者在另一个模块中?亲切的问候.Ivo – TMoover