9 unstable releases (3 breaking)

Uses old Rust 2015

0.4.0 Mar 5, 2018
0.3.2 Sep 19, 2017
0.3.0 Aug 20, 2017
0.2.4 Aug 10, 2017
0.1.0 Mar 7, 2017

#1353 in Encoding

Download history 111/week @ 2024-12-08 103/week @ 2024-12-15 39/week @ 2024-12-22 33/week @ 2024-12-29 61/week @ 2025-01-05 92/week @ 2025-01-12 132/week @ 2025-01-19 77/week @ 2025-01-26 90/week @ 2025-02-02 66/week @ 2025-02-09 104/week @ 2025-02-16 114/week @ 2025-02-23 74/week @ 2025-03-02 115/week @ 2025-03-09 71/week @ 2025-03-16 71/week @ 2025-03-23

339 downloads per month
Used in 2 crates

MIT license

33KB
701 lines

npy-rs

crates.io version Documentation Build Status

Numpy format (*.npy) serialization and deserialization.

NPY is a simple binary data format. It stores the type, shape and endianness information in a header, which is followed by a flat binary data field. This crate offers a simple, mostly type-safe way to read and write *.npy files. Files are handled using iterators, so they don't need to fit in memory.

Usage

To use npy-rs, two dependencies must be specified in Cargo.toml:

npy = "0.4"
npy-derive = "0.4"

A typical way to import everything needed is:

#[macro_use]
extern crate npy_derive;
extern crate npy;

The npy-derive dependency is only needed for structured array serialization.

Data can now be imported from a *.npy file:

use npy::NpyData;

std::fs::File::open("data.npy").unwrap().read_to_end(&mut buf).unwrap();
let data: Vec<f64> = NpyData::from_bytes(&buf).unwrap().to_vec();

and exported to a *.npy file:

npy::to_file("data.npy", data).unwrap();

See the documentation for more information.

Several usage examples are available in the examples directory; the simple example shows how to load a file, roundtrip shows both reading and writing. Large files can be memory-mapped as illustrated in the large example.

Documentation

Dependencies

~1.5MB
~24K SLoC