Skip to main content

interp

Function interp 

Source
pub fn interp(
    x: &Array<f64>,
    xp: &Array<f64>,
    fp: &Array<f64>,
    left: Option<f64>,
    right: Option<f64>,
) -> Array<f64>
Expand description

One-dimensional piecewise-linear interpolation, like np.interp(x, xp, fp, left, right).

xp must be increasing (not checked). Values of x below xp[0] give left and above xp[last] give right; both default to fp[0] and fp[last]. NaN in x gives NaN. The period argument is not supported. The output has the shape of x.

use rustnum as np;
let xp = np::array![1.0, 2.0, 3.0];
let fp = np::array![3.0, 2.0, 0.0];
let x = np::array![0.0, 1.5, 3.2];
assert_eq!(np::interp(&x, &xp, &fp, None, None).to_vec(), vec![3.0, 2.5, 0.0]);
assert_eq!(np::interp(&x, &xp, &fp, Some(-1.0), Some(9.0)).to_vec(), vec![-1.0, 2.5, 9.0]);