I'd like to access data in a C program that resides in a file that was written from python using numpy.save(...). So far, I was looking for a way to call the C version of numpy.load my C program, but it seems there is no directly accessible C version, because numpy.load uses the pickle module. Another solution would be to start an embedded python interpreter from C and call numpy.load in that interpreter, which should return the numpy array, which I can then access in the usual manner. However the last appraoch seems a bit to heavy, because I have to use the interpreter. Is there a better way to directly load the numpy array into C?
The .npy
format is not really meant to be read from outside NumPy. There are many formats available with provide both, excellent C and Python libraries, like HDF5 and NetCDF, so I can't see any reason whatsoever to access native NumPy files from C.
If you want to do this anyway, here are the docs of the .npy
format. It does not use pickle internally unless you stored Python objects in your array (but in that case, I would wonder what you are going to do with those in your C program).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With