Trait ndarray_npy::WriteNpyExt[][src]

pub trait WriteNpyExt {
    fn write_npy<W: Write>(&self, writer: W) -> Result<(), WriteNpyError>;
}
Expand description

Extension trait for writing ArrayBase to .npy files.

If writes are expensive (e.g. for a file or network socket) and the layout of the array is not known to be in standard or Fortran layout, it is strongly recommended to wrap the writer in a BufWriter. For the sake of convenience, this method calls .flush() on the writer before returning.

Example

use ndarray::{array, Array2};
use ndarray_npy::WriteNpyExt;
use std::fs::File;
use std::io::BufWriter;

let arr: Array2<i32> = array![[1, 2, 3], [4, 5, 6]];
let writer = BufWriter::new(File::create("array.npy")?);
arr.write_npy(writer)?;

Required methods

Writes the array to writer in .npy format.

This function is the Rust equivalent of numpy.save.

Implementations on Foreign Types

Implementors