[SciPy-user] Right way to import scipy

Robert Kern robert.kern at gmail.com
Mon Feb 20 21:35:46 CST 2006


Bill Baxter wrote:
> I posted this on the numpy list, but it seems more a scipy issue.
> 
> If you do this:
> 
> import numpy as N
> import scipy as S
> 
> Then S.linalg looks to be identical to N.linalg.  In particular it
> doesn't have things like lu, qr, gmres, etc.
> 
> If you subsequently do 'from scipy.linalg import lu', then suddenly
> S.linalg looks different from N.linalg, and it has not just lu, but all
> the other scipy linalg goodies too.
> 
> Is this a bug?  I would like to add info about getting at these
> functions to the Scipy for Matlab Users wiki page, but I'd like to know
> first if
> A) this is the expected behavior, or just a bug and

It's expected if you know what's going on, but not really desirable.
scipy/__init__.py does a "from numpy import *" which is pulling in the linalg
package. I'm pretty sure we don't want that. In fact, we already have a "del
lib" statement to clear that conflicting module, so we should just add a "del
linalg" statement, too.

> B) if these import statements are really the best way to get at
> scipy.linalg.lu <http://scipy.linalg.lu> et al.
>    import numpy as N
>    import scipy as S
>    from scipy.linalg import lu

Yup. Or just:

  from scipy.linalg import lu
  lu(A)

or even:

  from scipy import linalg
  linalg.lu(A)

-- 
Robert Kern
robert.kern at gmail.com

"In the fields of hell where the grass grows high
 Are the graves of dreams allowed to die."
  -- Richard Harter



More information about the SciPy-user mailing list