Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

why cannot I use sp.signal by import scipy as sp? [duplicate]

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)

The Kernel gives an error:

---> 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

Then, the script works,

tf = lti(numH, denH)

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

Thanks.

like image 894
Frank Zhao Avatar asked Sep 26 '22 09:09

Frank Zhao


1 Answers

From the scipy doc:

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

or from scipy import cluster.

There isn't much point to doing a simple

import scipy

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

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.

like image 142
hpaulj Avatar answered Sep 28 '22 22:09

hpaulj