I am doing some scientific computation, and I produce data with a C program and analyses using python. I want to export an array from C to python.
So far what I am doing is to write the C array, which is multidimensional (More than 2), into a csv file, and reading it from python np.genfromtxt and unwrapping it using the .reshape method. I think it would be a huge improvement if I could directly write a .npy file and call np.load. Is there any library in C that could do this?
CodePudding user response:
The NPY file format is an internal file format of Numpy. While there are few (non-standard) libraries like this or this or even this, the file format is relatively simple and documented by Numpy here. It can change in the future and the libraries may not be up to date.
Alternatively, a better solution is certainly to load/save your file using the HDF5 standard. It is widely supported by many fast/HPC libraries and supported by Numpy too (see this related post for more information). HDF5 also provide more advanced features like reading a slice or parallel read/writes for HPC applications.