Skip to main content

fix_invalid

Function fix_invalid 

Source
pub fn fix_invalid<T: Element + Float, D: Dimension>(
    data: &Array<T, D>,
    fill_value: T,
) -> FerrayResult<MaskedArray<T, D>>
Expand description

Create a MaskedArray by masking NaN and Inf values AND replacing them with fill_value in the underlying data.

Equivalent to numpy.ma.fix_invalid(data, fill_value=fill_value) (#510). This is a strict superset of masked_invalid: the result’s mask is identical (positions where x.is_nan() || x.is_infinite()) but the data array has those positions replaced with fill_value instead of the original NaN/Inf. The result’s fill_value is also set to fill_value so subsequent operations that use the fill value behave consistently.

Cleaning a data array in a single pass is the primary use case — after fix_invalid, the underlying data() is free of NaN/Inf and can be passed to operations that would otherwise produce NaN propagation.

§Errors

Returns an error only for internal failures (allocation).