Skip to main content

piecewise

Function piecewise 

Source
pub fn piecewise<T, D>(
    x: &Array<T, D>,
    condlist: &[Array<bool, D>],
    funclist: &[Box<dyn Fn(T) -> T>],
    default: T,
) -> FerrayResult<Array<T, D>>
where T: Element + Copy, D: Dimension,
Expand description

Evaluate a piecewise-defined function.

For each element position, the first condition in condlist that is true determines which function from funclist is applied. Elements where no condition is true receive the default value.

This is equivalent to numpy.piecewise(x, condlist, funclist).

§Arguments

  • x - The input array.
  • condlist - A slice of boolean arrays, each the same shape as x.
  • funclist - A slice of functions, one per condition. Each function maps T -> T.
  • default - The default value for elements where no condition is true.

§Errors

  • Returns FerrayError::InvalidValue if condlist and funclist have different lengths.
  • Returns FerrayError::ShapeMismatch if any condition array has a different shape than x.