#numpy #array #npy #data #npz #export #format

npy-writer

Export numpy arrays in the npy or npz format

3 releases

0.1.2 Dec 7, 2022
0.1.1 Dec 3, 2022
0.1.0 Nov 30, 2022

#2405 in Algorithms

Download history 1/week @ 2024-02-10 27/week @ 2024-02-17 36/week @ 2024-02-24 2/week @ 2024-03-02

66 downloads per month

MIT/Apache

12KB
296 lines

npy-writer

This is a small Rust package for writing the NumPy file formats .npy and .npz. This package supports writing the following data types:

  • Single floating points or integers
  • Vectors of single floating points or integers
  • N-dimensional arrays of single floating points or integers (via the ndarray feature)
  • npz files mapping string keys to any of the data types above (via the zip feature)

Usage

Example of writing a .npy file with integers:

use npy_writer::NumpyWriter;
use std::fs::File;

let mut f = File::create("out.npy").unwrap();
vec![3, 2, 1].write_npy(&mut f).unwrap();

With the feature ndarray, you can write N-dimensional arrays like so:

let mut arr = Array3::zeros((2, 3, 4));
arr.write_npy(&mut f).unwrap();

Dependencies

~0–1MB
~16K SLoC