Struct MaskedArray

Source
pub struct MaskedArray<A, S, D>
where A: Clone, S: Data<Elem = A> + Clone + RawDataClone, D: Dimension,
{ pub data: ArrayBase<S, D>, pub mask: Array<bool, D>, pub fill_value: A, }
Expand description

Represents an array with a mask to identify invalid or missing values

Fields§

§data: ArrayBase<S, D>

The underlying data array

§mask: Array<bool, D>

The mask array: true = masked (invalid), false = valid

§fill_value: A

The fill value used when creating a filled array

Implementations§

Source§

impl<A, S, D> MaskedArray<A, S, D>
where A: Clone + PartialEq, S: Data<Elem = A> + Clone + RawDataClone, D: Dimension,

Source

pub fn new( data: ArrayBase<S, D>, mask: Option<Array<bool, D>>, fill_value: Option<A>, ) -> Result<Self, ArrayError>

Create a new MaskedArray from data and mask

§Errors

Returns ArrayError::ShapeMismatch if the mask shape doesn’t match the data shape.

Source

pub fn filled(&self, fill_value: Option<A>) -> Array<A, D>
where <D as Dimension>::Pattern: NdIndex<D>,

Get a view of the data with masked values replaced by fill_value

Source

pub fn has_masked(&self) -> bool

Returns true if the array has at least one masked element

Source

pub fn count(&self) -> usize

Returns the count of non-masked elements

Source

pub fn get_mask(&self) -> Array<bool, D>

Get a copy of the current mask

Source

pub fn set_mask(&mut self, mask: Array<bool, D>) -> Result<(), ArrayError>

Set a new mask for the array

§Errors

Returns ArrayError::ShapeMismatch if the mask shape doesn’t match the data shape.

Source

pub fn set_fill_value(&mut self, fill_value: A)

Set the fill value for the array

Source

pub fn compressed(&self) -> Array<A, Ix1>

Returns a new array containing only unmasked values

Source

pub fn shape(&self) -> &[usize]

Returns the shape of the array

Source

pub fn ndim(&self) -> usize

Returns the number of dimensions of the array

Source

pub fn size(&self) -> usize

Returns the number of elements in the array

Source

pub const fn data_and_mask(&self) -> (&ArrayBase<S, D>, &Array<bool, D>)

Returns a tuple of (data, mask)

Source

pub fn mask_op<F>(&self, op: F) -> Self
where F: Fn(&Array<bool, D>) -> Array<bool, D>,

Creates a new masked array with the given mask operation applied

Source

pub fn harden_mask(&self) -> Self

Creates a new masked array with a hardened mask (copy)

Source

pub fn soften_mask(&self) -> Self

Create a new masked array with a softened mask (copy)

Source

pub fn mask_where<F>(&self, condition: F) -> Self
where F: Fn(&A) -> bool,

Create a new masked array where the result of applying the function to each element is masked

Source

pub fn mask_or(&self, other_mask: &Array<bool, D>) -> Result<Self, ArrayError>

Create a logical OR of the mask with another mask

§Errors

Returns ArrayError::ShapeMismatch if the mask shapes don’t match.

Source

pub fn mask_and(&self, other_mask: &Array<bool, D>) -> Result<Self, ArrayError>

Create a logical AND of the mask with another mask

§Errors

Returns ArrayError::ShapeMismatch if the mask shapes don’t match.

Source

pub fn reshape<E>( &self, shape: E, ) -> Result<MaskedArray<A, OwnedRepr<A>, E>, ArrayError>
where E: Dimension, D: Dimension,

Reshape the masked array

§Errors

Returns ArrayError::ValueError if the reshape operation fails.

Source

pub fn astype<B>(&self) -> Result<MaskedArray<B, OwnedRepr<B>, D>, ArrayError>
where A: Into<B> + Clone, B: Clone + PartialEq + 'static,

Convert to a different type

§Errors

Currently this method doesn’t return errors, but the signature is kept for future compatibility.

Source§

impl<A, S, D> MaskedArray<A, S, D>
where A: Clone + PartialEq + NumAssign + Zero + One + PartialOrd, S: Data<Elem = A> + Clone + RawDataClone, D: Dimension,

Implementation of statistical methods

Source

pub fn sum(&self) -> A

Compute the sum of all unmasked elements

Source

pub fn product(&self) -> A

Compute the product of all unmasked elements

Source

pub fn min(&self) -> Option<A>

Find the minimum value among unmasked elements

Source

pub fn max(&self) -> Option<A>

Find the maximum value among unmasked elements

Source

pub fn argmin(&self) -> Option<usize>

Find the index of the minimum value among unmasked elements

Source

pub fn argmax(&self) -> Option<usize>

Find the index of the maximum value among unmasked elements

Source§

impl<A, S, D> MaskedArray<A, S, D>
where A: Clone + PartialEq + Float + Sum<A>, S: Data<Elem = A> + Clone + RawDataClone, D: Dimension,

Implementation of statistical methods for floating point types

Source

pub fn mean(&self) -> Option<A>

Compute the mean of all unmasked elements

§Panics

Panics if the count cannot be converted to type A.

Source

pub fn var(&self, ddof: usize) -> Option<A>

Compute the variance of all unmasked elements

§Panics

Panics if the count cannot be converted to type A.

Source

pub fn std(&self, ddof: usize) -> Option<A>

Compute the standard deviation of all unmasked elements

Source

pub fn all_finite(&self) -> bool

Check if all unmasked elements are finite

Trait Implementations§

Source§

impl<A, S1, S2, D> Add<&MaskedArray<A, S2, D>> for &MaskedArray<A, S1, D>
where A: Clone + Add<Output = A> + PartialEq, S1: Data<Elem = A> + Clone + RawDataClone, S2: Data<Elem = A> + Clone + RawDataClone, D: Dimension,

Source§

type Output = MaskedArray<A, OwnedRepr<A>, D>

The resulting type after applying the + operator.
Source§

fn add(self, rhs: &MaskedArray<A, S2, D>) -> Self::Output

Performs the + operation. Read more
Source§

impl<A, S, D> Clone for MaskedArray<A, S, D>
where A: Clone + Clone, S: Data<Elem = A> + Clone + RawDataClone + Clone, D: Dimension + Clone,

Source§

fn clone(&self) -> MaskedArray<A, S, D>

Returns a duplicate of the value. Read more
1.0.0 · Source§

const fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<A, S, D> Debug for MaskedArray<A, S, D>
where A: Clone + PartialEq + Debug, S: Data<Elem = A> + Clone + RawDataClone, D: Dimension,

Implementation of Debug for MaskedArray

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<A, S, D> Display for MaskedArray<A, S, D>
where A: Clone + PartialEq + Display, S: Data<Elem = A> + Clone + RawDataClone, D: Dimension,

Implementation of Display for MaskedArray

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<A, S1, S2, D> Div<&MaskedArray<A, S2, D>> for &MaskedArray<A, S1, D>
where A: Clone + Div<Output = A> + PartialEq + Zero, S1: Data<Elem = A> + Clone + RawDataClone, S2: Data<Elem = A> + Clone + RawDataClone, D: Dimension,

Source§

type Output = MaskedArray<A, OwnedRepr<A>, D>

The resulting type after applying the / operator.
Source§

fn div(self, rhs: &MaskedArray<A, S2, D>) -> Self::Output

Performs the / operation. Read more
Source§

impl<A, S1, S2, D> Mul<&MaskedArray<A, S2, D>> for &MaskedArray<A, S1, D>
where A: Clone + Mul<Output = A> + PartialEq, S1: Data<Elem = A> + Clone + RawDataClone, S2: Data<Elem = A> + Clone + RawDataClone, D: Dimension,

Source§

type Output = MaskedArray<A, OwnedRepr<A>, D>

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: &MaskedArray<A, S2, D>) -> Self::Output

Performs the * operation. Read more
Source§

impl<A, S1, S2, D> Sub<&MaskedArray<A, S2, D>> for &MaskedArray<A, S1, D>
where A: Clone + Sub<Output = A> + PartialEq, S1: Data<Elem = A> + Clone + RawDataClone, S2: Data<Elem = A> + Clone + RawDataClone, D: Dimension,

Source§

type Output = MaskedArray<A, OwnedRepr<A>, D>

The resulting type after applying the - operator.
Source§

fn sub(self, rhs: &MaskedArray<A, S2, D>) -> Self::Output

Performs the - operation. Read more

Auto Trait Implementations§

§

impl<A, S, D> Freeze for MaskedArray<A, S, D>
where A: Freeze, S: Freeze, D: Freeze,

§

impl<A, S, D> RefUnwindSafe for MaskedArray<A, S, D>

§

impl<A, S, D> Send for MaskedArray<A, S, D>
where A: Send, S: Send,

§

impl<A, S, D> Sync for MaskedArray<A, S, D>
where A: Sync, S: Sync,

§

impl<A, S, D> Unpin for MaskedArray<A, S, D>
where A: Unpin, S: Unpin, D: Unpin,

§

impl<A, S, D> UnwindSafe for MaskedArray<A, S, D>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V