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>>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 asx.funclist- A slice of functions, one per condition. Each function mapsT -> T.default- The default value for elements where no condition is true.
§Errors
- Returns
FerrayError::InvalidValueifcondlistandfunclisthave different lengths. - Returns
FerrayError::ShapeMismatchif any condition array has a different shape thanx.