Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/potocpav/npy-rs
NumPy file format (de-)serialization in Rust
https://github.com/potocpav/npy-rs
numpy rust serialization
Last synced: about 2 months ago
JSON representation
NumPy file format (de-)serialization in Rust
- Host: GitHub
- URL: https://github.com/potocpav/npy-rs
- Owner: potocpav
- Created: 2017-03-07T14:17:39.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2019-07-15T14:57:22.000Z (over 5 years ago)
- Last Synced: 2024-11-01T07:41:04.015Z (about 2 months ago)
- Topics: numpy, rust, serialization
- Language: Rust
- Size: 97.7 KB
- Stars: 30
- Watchers: 4
- Forks: 7
- Open Issues: 12
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# npy-rs
[![crates.io version](https://img.shields.io/crates/v/npy.svg)](https://crates.io/crates/npy) [![Documentation](https://docs.rs/npy/badge.svg)](https://docs.rs/npy/) [![Build Status](https://travis-ci.org/potocpav/npy-rs.svg?branch=master)](https://travis-ci.org/potocpav/npy-rs)Numpy format (*.npy) serialization and deserialization.
[**NPY**](https://docs.scipy.org/doc/numpy-dev/neps/npy-format.html) 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`:
```toml
npy = "0.4"
npy-derive = "0.4"
```A typical way to import everything needed is:
```rust
#[macro_use]
extern crate npy_derive;
extern crate npy;
```The `npy-derive` dependency is only needed for
[structured array](https://docs.scipy.org/doc/numpy/user/basics.rec.html)
serialization.Data can now be imported from a `*.npy` file:
```rust
use npy::NpyData;std::fs::File::open("data.npy").unwrap().read_to_end(&mut buf).unwrap();
let data: Vec = NpyData::from_bytes(&buf).unwrap().to_vec();```
and exported to a `*.npy` file:
```
npy::to_file("data.npy", data).unwrap();
```See the [documentation](https://docs.rs/npy/) for more information.
Several usage examples are available in the
[examples](https://github.com/potocpav/npy-rs/tree/master/examples) directory; the
[simple](https://github.com/potocpav/npy-rs/blob/master/examples/simple.rs) example shows how to load a file, [roundtrip](https://github.com/potocpav/npy-rs/blob/master/examples/roundtrip.rs) shows both reading
and writing. Large files can be memory-mapped as illustrated in the
[large example](https://github.com/potocpav/npy-rs/blob/master/examples/large.rs).[Documentation](https://docs.rs/npy/)