martina.physics
martina.physics

Reputation: 9804

What Scipy modules are actually calls to Numpy ones?

I am confused by the fact that some modules in Scipy are not actually part of the library but are rather calls to modules in Numpy.

One example for all is linalg:

import scipy
scipy.linalg

this gives

AttributeError: 'module' object has no attribute 'linalg'

on the flip side, the right way to call it from Scipy is

from scipy import linalg
scipy.linalg

which must be a handle for

numpy.linalg

How does this work? And technically what distinguishes Numpy and Scipy then?

Upvotes: 4

Views: 108

Answers (1)

user2357112
user2357112

Reputation: 282198

the right way to call it from Scipy is

from scipy import linalg
scipy.linalg

which must be a handle for

numpy.linalg

Nope! They're totally different modules. Also, it'd be either import scipy.linalg and then use scipy.linalg, or from scipy import linalg and then use linalg.

If you want to tell whether a SciPy module is actually from NumPy, the easiest way is to just look at it interactively:

In [9]: scipy.random
Out[9]: <module 'numpy.random' from '/usr/local/lib/python2.7/dist-packages/numpy/random/__init__.pyc'>

In [10]: scipy.linalg
Out[10]: <module 'scipy.linalg' from '/usr/local/lib/python2.7/dist-packages/scipy/linalg/__init__.pyc'>

As you can see, the one from numpy says numpy in the output. This is an IPython session, but a regular Python interactive session will say something similar.

Upvotes: 3

Related Questions