为什么我会收到此错误?AttributeError: 'module' 对象没有属性 'periodogram' [英] Why am I geting this error? AttributeError: 'module' object has no attribute 'periodogram'

查看:67
本文介绍了为什么我会收到此错误?AttributeError: 'module' 对象没有属性 'periodogram'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我复制了以下几行

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 但是当我尝试运行代码时,我收到此错误:

from **http://docs.scipy.org/doc/scipy/reference/generated/scipy.signal.periodogram.html#scipy.signal.periodogram but when I try to run the code I'm getting this error:

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

我使用的是 Scipy 0.12 版感谢您的帮助.亲切的问候.伊沃

I'm using Scipy version 0.12 Thank your for your help. Kind Regards. Ivo

推荐答案

>>>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 通常,当我在安装或导入您认为已正确安装的模块时遇到困难时,我通常会首先访问该站点.

You definitely have something wrong with your installation of scipy. I recommend http://www.lfd.uci.edu/~gohlke/pythonlibs/#scipy this site in general is usually my first place to go when having difficulty installing or importing modules that you believe to be installed correctly.

网站上的内容列表并不是所有内容的 100%,而是您可以在那里找到的大部分重要内容.

The list of stuff on the website is not 100% of everything, but most of the big important stuff you can find there.

这篇关于为什么我会收到此错误?AttributeError: 'module' 对象没有属性 'periodogram'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆