use ndarray::{array, Array1, Array2}; use ndarray_npy::{NpzReader, NpzWriter}; use std::fs::File; fn write_example() -> Result<(), Box> { let mut npz = NpzWriter::new(File::create("arrays.npz")?); let a: Array2 = array![[1, 2, 3], [4, 5, 6]]; let b: Array1 = array![7, 8, 9]; npz.add_array("a", &a)?; npz.add_array("b", &b)?; npz.finish()?; Ok(()) } fn read_example() -> Result<(), Box> { let mut npz = NpzReader::new(File::open("arrays.npz")?)?; let a: Array2 = npz.by_name("a")?; let b: Array1 = npz.by_name("b")?; println!("a =\n{}", a); println!("b =\n{}", b); Ok(()) } fn main() { write_example().expect("failure writing arrays to file"); read_example().expect("failure reading arrays from file"); }