pub struct NpzReader<R: Read + Seek> { /* private fields */ }
Expand description
Reader for .npz
files.
§Example
use ndarray::{Array1, Array2};
use ndarray_npy::NpzReader;
use std::fs::File;
let mut npz = NpzReader::new(File::open("arrays.npz")?)?;
let a: Array2<i32> = npz.by_name("a")?;
let b: Array1<i32> = npz.by_name("b")?;
Implementations§
Source§impl<R: Read + Seek> NpzReader<R>
impl<R: Read + Seek> NpzReader<R>
Sourcepub fn new(reader: R) -> Result<NpzReader<R>, ReadNpzError>
pub fn new(reader: R) -> Result<NpzReader<R>, ReadNpzError>
Creates a new .npz
file reader.
Sourcepub fn names(&mut self) -> Result<Vec<String>, ReadNpzError>
pub fn names(&mut self) -> Result<Vec<String>, ReadNpzError>
Returns the names of all of the arrays in the file.
Note that a single “.npy” suffix (if present) will be stripped from each name; this matches NumPy’s behavior.
Sourcepub fn by_name<S, D>(
&mut self,
name: &str,
) -> Result<ArrayBase<S, D>, ReadNpzError>
pub fn by_name<S, D>( &mut self, name: &str, ) -> Result<ArrayBase<S, D>, ReadNpzError>
Reads an array by name.
Note that this first checks for name
in the .npz
file, and if that is not present,
checks for format!("{name}.npy")
. This matches NumPy’s behavior.
Auto Trait Implementations§
impl<R> Freeze for NpzReader<R>where
R: Freeze,
impl<R> RefUnwindSafe for NpzReader<R>where
R: RefUnwindSafe,
impl<R> Send for NpzReader<R>where
R: Send,
impl<R> Sync for NpzReader<R>where
R: Sync,
impl<R> Unpin for NpzReader<R>where
R: Unpin,
impl<R> UnwindSafe for NpzReader<R>where
R: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more