pub struct NpyData<'a, T: Deserialize> { /* private fields */ }
Expand description
Legacy type for reading npy
files.
This type provides the same API for reading from
npy-rs 0.4.0
, to help with migration. It will later be removed in favor ofNpyFile
.
The data is internally stored
as a byte array, and deserialized only on-demand to minimize unnecessary allocations.
The whole contents of the file can be deserialized by the NpyData::to_vec
method.
Implementations§
source§impl<'a, T: Deserialize> NpyData<'a, T>
impl<'a, T: Deserialize> NpyData<'a, T>
sourcepub fn from_bytes(bytes: &'a [u8]) -> Result<NpyData<'a, T>>
pub fn from_bytes(bytes: &'a [u8]) -> Result<NpyData<'a, T>>
Deserialize a NPY file represented as bytes
sourcepub fn is_empty(&self) -> bool
pub fn is_empty(&self) -> bool
Returns whether there are zero records in this NpyData structure.
sourcepub fn get(&self, i: usize) -> Option<T>
pub fn get(&self, i: usize) -> Option<T>
Gets a single data-record with the specified flat index.
Returns None if the index is out of bounds.
Panics
Panics if the bytes stored for the element are invalid for the dtype.
sourcepub fn get_unchecked(&self, i: usize) -> T
pub fn get_unchecked(&self, i: usize) -> T
Gets a single data-record with the specified index.
Panics
Panics if the bytes stored for the element are invalid for the dtype, or if the index is out of bounds.
sourcepub fn to_vec(&self) -> Vec<T>
pub fn to_vec(&self) -> Vec<T>
Construct a vector with the deserialized contents of the whole file.
The output is a flat vector with the elements in the same order that they are in the file.
NpyData
is deprecated and does not provide any tools for inspecting the shape and
layout of the data, so if you want to correctly read multi-dimensional arrays you should
switch to NpyFile
.