In the tutorial of the Cython documentation, there are cimport and import statements of numpy module:
import numpy as np
cimport numpy as np
I found this convention is quite popular among numpy/cython users.
This looks strange for me because they are both named as np. In which part of the code, imported/cimported np are used? Why cython compiler does not confuse them?
cimportdoesn't really import a (Python) module. It imports (C) definitions. I don't know, but I could imagine that if you turn the second line intocimport numpyonly, things would break: it may very well need the correspondonce between the actual Python module name as used in the script, and the definitions namespace. - user707650cimport numpy, in the same way that one could useimport numpy, it works just the same way, butcimportgives access to C functions or attributes under the imported module whileimportto Python functions or attributes - Saullo G. P. Castro