mrKelley
mrKelley

Reputation: 3534

How do I read numpy source?

I built it myself on Python 3.3, but I can't for the life of me find the class definition of numpy.array(). I've looked all through the code and even found the core C files, but where is the dang array class??

Can anyone tell me what directory to look in, or how to find out from the python shell?

Upvotes: 27

Views: 10381

Answers (1)

wim
wim

Reputation: 362945

  • np.array is not a class itself, it's just a convenience function to create an np.ndarray.
  • ndarray is aliased to multiarray, which is implemented in C code (an extension module in .so/.pyd file, compiled code).
  • You can start looking at the ndarray interfaces here in numeric.py.
  • Most of the meat of the implementation is in C code, here in multiarray.
  • array() is implemented in _core/src/multiarray/methods.c in array_getarray().

Upvotes: 45

Related Questions