When I say import numpy as np
, I can access all the modules and submodules in numpy from np. I do not have to say np.matrixlib.matrix
. What is this feature called? How do I implement this in my package.
Asked
Active
Viewed 73 times
-2

Gerard Puts
- 3
- 1
-
I don't think your statement " I can access all the modules and submodules in numpy from np" is correct (I am not quite sure what you mean exactly), but consider `np.random.normal` which cannot be accessed through `np.normal` – FlyingTeller Aug 17 '18 at 11:22
-
You could just check how numpy [does it](https://github.com/numpy/numpy/blob/master/numpy/__init__.py) – FlyingTeller Aug 17 '18 at 11:28
2 Answers
0
If one want's that submodules are available in the main module, they have to be imported in __init__.py
.
See for example numpy/__init__.py
:
from .matrixlib import *
imports everything from numpy.matrixlib
into numpy
.

Daniel
- 42,087
- 4
- 55
- 81
-1
I think you mean something like:
from numpy import *
Although I think this may only do the first level of functions. You might need another one for the 'deeper' functions:
from numpy.matrixlib import matrix

N Chauhan
- 3,407
- 2
- 7
- 21
-
Doing `import numpy as np` enables one to write`np.matrix` instead of having to import it seperately – FlyingTeller Aug 17 '18 at 11:41