pub trait WriteNpyExt {
// Required method
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§
Sourcefn write_npy<W: Write>(&self, writer: W) -> Result<(), WriteNpyError>
fn write_npy<W: Write>(&self, writer: W) -> Result<(), WriteNpyError>
Writes the array to writer
in .npy
format.
This function is the Rust equivalent of
numpy.save
.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.