pub struct NpyArray {
pub dtype: NpyDtype,
pub shape: Vec<usize>,
pub data_f64: Vec<f64>,
pub data_f32: Vec<f32>,
pub data_i32: Vec<i32>,
}Expand description
An in-memory NumPy array.
Only one of data_f64, data_f32, or data_i32 is populated,
depending on dtype.
Fields§
§dtype: NpyDtypeElement type.
shape: Vec<usize>Shape (row-major), e.g. \[3, 2\] for a 3×2 matrix.
data_f64: Vec<f64>Float64 payload (populated when dtype == Float64).
data_f32: Vec<f32>Float32 payload (populated when dtype == Float32).
data_i32: Vec<i32>Int32 payload (populated when dtype == Int32).
Implementations§
Source§impl NpyArray
impl NpyArray
Sourcepub fn from_f64(shape: Vec<usize>, data: Vec<f64>) -> Self
pub fn from_f64(shape: Vec<usize>, data: Vec<f64>) -> Self
Create an NpyArray from f64 data and shape.
Sourcepub fn from_f32(shape: Vec<usize>, data: Vec<f32>) -> Self
pub fn from_f32(shape: Vec<usize>, data: Vec<f32>) -> Self
Create an NpyArray from f32 data and shape.
Source§impl NpyArray
impl NpyArray
Sourcepub fn save_structured(
fields: &[(&str, &str)],
n_records: usize,
data_bytes: &[u8],
) -> Result<Vec<u8>, String>
pub fn save_structured( fields: &[(&str, &str)], n_records: usize, data_bytes: &[u8], ) -> Result<Vec<u8>, String>
Serialize a structured array with named fields to NPY v1.0 bytes.
fields is a slice of (name, dtype_str) pairs, e.g.
&\[("x", "<f8"), ("y", "<f8")\]. The data must be already packed
in record order (all fields of record 0, then record 1, …).
Returns the NPY bytes suitable for writing to a .npy file.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for NpyArray
impl RefUnwindSafe for NpyArray
impl Send for NpyArray
impl Sync for NpyArray
impl Unpin for NpyArray
impl UnsafeUnpin for NpyArray
impl UnwindSafe for NpyArray
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
The inverse inclusion map: attempts to construct
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
Checks if
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
Use with care! Same as
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
The inclusion map: converts
self to the equivalent element of its superset.