Load a numpy array in C from a file that was saved using numpy.save (...)

I would like to access data in a C program that is in a file written with python using numpy.save (...). So far I have been looking for a way to call the c version of numpy.load my C program, but there seems to be no direct version of C, because numpy.load uses the pickle module. Another solution would be to run the python built-in interpreter from C and call numpy.load in that interpreter, which should return a numpy array that I can access in the usual way. However, the last certificate seems a bit heavy because I have to use an interpreter. Is there a better way to directly load a numpy array in C?

+4
source share
3 answers

The .npy format .npy not intended to be read from outside NumPy. There are many formats available that provide both excellent C libraries and Python such as HDF5 and NetCDF, so I see no reason to access my own NumPy files with C.

If you want to do this anyway, .npy format .npy . It does not use pickle internally unless you have stored Python objects in your array (but in this case, I wonder what you are going to do with the ones in your C program).

+3
source

You should check out this little lib. I found this quite useful.

https://github.com/rogersce/cnpy

+10
source

Source: https://habr.com/ru/post/1343805/


All Articles