-1

I have this code from scikit docs:

import numpy as np
np.random.seed(1)

I understand what this code does semantically, but I cannot understand what this code actually calls.

Ok, numpy is a name of python module and np is just an alias for that. But what is np.random? Is it module inside of another module?

I found source code on GitHub and random is just a folder inside of numpy directory. So numpy should be a package, not a module?

vector2718
  • 47
  • 4
  • See the [`numpy.random.seed()` documentation](https://docs.scipy.org/doc/numpy/reference/generated/numpy.random.seed.html#numpy.random.seed). Does it matter much how the packages and modules are arranged? – Martijn Pieters Jan 05 '17 at 09:29
  • 1
    possible duplicate of http://stackoverflow.com/questions/7948494/whats-the-difference-between-a-python-module-and-a-python-package – lhk Jan 05 '17 at 09:48
  • You seem to be answering your own question. What exactly is the source of your confusion? – juanpa.arrivillaga Jan 05 '17 at 10:37
  • @juanpa.arrivillaga I think I was confused because I didn't know that it's possible to import package too. – vector2718 Jan 05 '17 at 10:50
  • @vector2718 Then what purpose did you think a package served? In other words, what else would you do with a package? – juanpa.arrivillaga Jan 05 '17 at 11:00
  • 2
    Or perhaps it is enlightening to understand that technically, you import whatever is in the `__init__.py` special module in the package directory when you `import package`. – juanpa.arrivillaga Jan 05 '17 at 11:02
  • @juanpa.arrivillaga I thought packages are just for namespace naming. Like packages in Java. – vector2718 Jan 05 '17 at 11:13
  • Technically, at runtime, a "package" is just a `module` object built from the package's `__init__.py`. Any name defined in the `__init__.py` will then become an attribute of this module - as usual for each and any module. – bruno desthuilliers Jan 05 '17 at 11:37

1 Answers1

0

Numpy is a package, that contains module random which contains method seed.

Christian W.
  • 2,532
  • 1
  • 19
  • 31