Read and write .npy
and .npz
files in C++. Forked from rogersce/cnpy, added an example project showing how this library can be used as a dependency. For converting .mat
files to .npz
and vice versa, use npy_mat_npz.
git clone https://github.com/saravanabalagi/cnpy.git
sh build.sh
For reading data:
- npy_load(f)
- npz_load(f)
- npz_load(f, var)
Once loaded into, say cnpy::NpyArray np_data
variable, you can retrieve
np_data.data<T>()
yields data pointerT*
, where T can beint
,double
, etc.np_data.shape
yieldsstd::vector<size_t> shape
;np_data.word_size
yieldssize_t word_size
;
For saving data:
- npy_save(f, data, shape)
- npz_save(f, var, data, shape)
example shows how to use this lib in your own projects and example.cpp has code to read and write sample numpy arrays.