1

I am using numpy in Cython mostly by looking at examples on the net / SO:

cimport cython
import numpy as np
cimport numpy as np
from numpy cimport ndarray as ar
....
... = np.empty(...)
...
cdef ar[double, ndim=1, mode='c'] y = ....
...
... = np.argmax(...)

Suppose, now I make the change cimport numpy as np to cimport numpy as cnp. Then how do I know which functions (i.e. np.empty, np.argmax, etc.) in the code above rely on np versus which functions rely on cnp ?

uday
  • 6,453
  • 13
  • 56
  • 94
  • First, try to see from where np is loaded, it should be overwritten to cython module as both of them having the same name . – mitghi Jun 27 '15 at 16:12
  • i didn't quite understand. what do you mean by "try to see from where np is loaded" ? – uday Jun 27 '15 at 16:15
  • print np.__file__. If it is from .so file or pyx, then cython module is the only one available and you can assume all of them relies on cython module. – mitghi Jun 27 '15 at 16:16
  • aren't cython codes all compiled? if i try `cimport numpy as np` in an interactive mode it gives me an error. – uday Jun 27 '15 at 16:23
  • either compile the code and run np.__file__ or use pyximport to compile it at runtime, but then you should put cimport statements in a seperate pyx file. – mitghi Jun 27 '15 at 16:25
  • 1
    thanks, I did it. and then `np.__file__` shows me the `...numpy\\__init__.py`. now, how do i know if the `np.empty`, `np.argmax` in the cython code are using the `np` from `import numpy as np` or `cimport numpy as np` ? – uday Jun 27 '15 at 16:40

0 Answers0