In some use cases, we would like to load and save Numpy files in C++ applications. This repository provides examples to load and save Numpy files using the xtensor library.
To build the Docker image, please run the following command.
$ docker build -f docker/xtensor.Dockerfile --tag xtensor:24.04 .
To run the Docker container, please run the following command.
$ docker run -it --rm -v $(pwd):/mnt -w /mnt xtensor:24.04
To build the examples, please run the following commands.
$ cmake -B build
$ cmake --build build --config Release --parallel
To run the examples, please run the following commands.
$ mkdir -p data
# Save npy file from Python
$ python python/save_npy.py --npy_file_path data/npy_data_from_python.npy
# Verify npy file from Python
$ python python/load_npy.py --npy_file_path data/npy_data_from_python.npy
# Verify npy file from C++
$ ./build/src/load_npy data/npy_data_from_python.npy
# Save npy file from C++
$ ./build/src/save_npy data/npy_data_from_cpp.npy
# Verify npy file from Python
$ python python/load_npy.py --npy_file_path data/npy_data_from_cpp.npy
# Verify npy file from C++
$ ./build/src/load_npy data/npy_data_from_cpp.npy