Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I read numpy source?

Tags:

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?

like image 622
mrKelley Avatar asked May 22 '13 02:05

mrKelley


People also ask

Where is NumPy source code?

C:\Users\<name>\AppData\Local\Programs\Python\Python37-32\Lib\site-packages\numpy\core\multiarray.py is where I found it.

How do I convert NPY to CSV?

You can save your NumPy arrays to CSV files using the savetxt() function. This function takes a filename and array as arguments and saves the array into CSV format. You must also specify the delimiter; this is the character used to separate each variable in the file, most commonly a comma.


1 Answers

  • np.array is not a class itself, just a convenience function to create an np.ndarray
  • ndarray is just aliased to multiarray, which is implemented in C code (I think in an .so i.e. shared object, 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()
like image 101
wim Avatar answered Oct 12 '22 23:10

wim