Reputation: 283
If I run the following two lines of code:
import numpy
numpy.linalg
I do not get an error, and I get the output <module 'numpy.linalg' from /Users/...>
.
However, if I run the following two lines of code
import scipy
scipy.linalg
I get the error
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-7-7ed633b28ccc> in <module>
1 import scipy
----> 2 scipy.linalg
AttributeError: module 'scipy' has no attribute 'linalg'
However, the following code seems to work fine:
import scipy.linalg
scipy.linalg
My question is: how come after importing numpy
, I can use numpy.linalg
, but I can't do the same for scipy
?
For context, I am using numpy version 1.19.2, and I am using scipy version 1.4.1.
Upvotes: 1
Views: 6004
Reputation: 57105
There is a line in "numpy/__init__.py", which is the module initialization file, that explicitly imports linalg
:
from . import linalg
There is no such line in "scipy/__init__.py". That is why you must import scipy.linalg
yourself.
Upvotes: 5