为什么我不能通过 import scipy as sp 使用 sp.signal? [英] why cannot I use sp.signal by import scipy as sp?

查看:107
本文介绍了为什么我不能通过 import scipy as sp 使用 sp.signal?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用 scipy.signal.ltiscipy.signal.impulse 函数来计算传递函数.我通过以下方式导入 scipy 模块.

I would like to use scipy.signal.lti and scipy.signal.impulse function to calculate the transfer function. I import the scipy module in the following way.

import scipy as sp
import numpy as np
import matplotlib.pyplot as plt
from math import *

但是,当我输入以下脚本时,

However, when I type the following scripts,

tf = sp.signal.lti(numH, denH)

内核报错:

---> 10 tf = sp.signal.lti(numH, denH)
AttributeError: 'module' object has no attribute 'signal' 

我尝试了另一种方式导入信号模块,

I tried another way to import the signal module,

from scipy.signal import lti, step, impulse

然后,脚本工作,

tf = lti(numH, denH)

那么,我的问题是,我们是否必须导入脚本中的每个子包?那么导入scipy包有什么意义?

So, my questions is, must we import every subpackage in the script? Then what's the point of importing the scipy package?

谢谢.

推荐答案

来自 scipy 文档:

使用这些子包中的任何一个都需要显式导入.例如,导入scipy.cluster.

Using any of these subpackages requires an explicit import. For example, import scipy.cluster.

from scipy import cluster.

做一个简单的事情没有多大意义

There isn't much point to doing a simple

import scipy

查看 site-packages/scipy/__init__.py 文件了解更多详情.将它与 numpy init 进行比较.

Look at the site-packages/scipy/__init__.py file for more details. Compare it with the numpy init.

numpy 是一个集成包,scipy 是松散集成包的集合.numpy 是大家使用的基本数字包.scipy 子包相对独立.我可以在不了解 signalintegrate 包的情况下加载和使用 sparse.

numpy is an integrated package, scipy is a collection of loosely integrated packages. numpy is the basic numeric package that everyone uses. The scipy subpackages are relatively independent of each other. I can load and use sparse without knowning anything about the signal or integrate packages.

这篇关于为什么我不能通过 import scipy as sp 使用 sp.signal?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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