npio is a C library for reading and writing .npy files.
It supports arrays with a single data type, i.e., not structured arrays.
To communicate data with Python without adding a large dependency, while eliminating the risk of silly mistakes that can happen when sharing raw data files with no encoded metadata.
For what has been done, see the CHANGELOG.
-
Always saves arrays with
'fortran_order': False, i.e. up to the user to navigate around this if it is a problem. -
Ignores the byte order. The code is only run on little endian machines (AARCH64, x86_64) (to do).
-
Decide for a better way to communicate errors without relying on
stdout. -
Facilitate memory mapping of the data.
-
Load data to a user-provided buffer.
-
NPZ support using libzip.
- Supported nested arrays, and for the same reason there is no point in supporting Numpy files of version 2.0 ( > 65535 bytes header length).
Start with
#include <npio.h>Open an npy file and print the some info to stdout:
npio_t * np = npio_load(filename);
if(np)
{
npio_print(stdout, np);
npio_free(np);
}Write an array to a file:
npio_write("array.npy",
ndim, &shape,
array,
NPIO_F32, NPIO_F32);To build and install as a shared library, use the CMakeLists.txt:
mkdir build
cd build
cmake ../
make
sudo make installAlternatively copy and add npio.h, npio.c and npio_config.h to
your project.
Some self-tests can be run with ./npio --unittest. A few more cases
are covered by the Python script npio_test_suite.py.