Cython: cimport and import numpy as (both) np

后端 未结 1 509
别那么骄傲
别那么骄傲 2020-12-05 06:50

In the tutorial of the Cython documentation, there are cimport and import statements of numpy module:

import numpy as np
cimport numpy as np
<
相关标签:
1条回答
  • 2020-12-05 07:29

    cimport my_module gives access to C functions or attributes or even sub-modules under my_module

    import my_module gives access to Python functions or attributes or sub-modules under my_module.

    In your case:

    cimport numpy as np
    

    gives you access to Numpy C API, where you can declare array buffers, variable types and so on...

    And:

    import numpy as np
    

    gives you access to NumPy-Python functions, such as np.array, np.linspace, etc

    Cython internally handles this ambiguity so that the user does not need to use different names.

    0 讨论(0)
提交回复
热议问题