quantile

Function quantile 

Source
pub fn quantile<T>(
    array: ArrayView<'_, T, Ix1>,
    q: ArrayView<'_, T, Ix1>,
    method: Option<&str>,
) -> Result<Array<T, Ix1>, &'static str>
where T: Clone + Float + FromPrimitive,
Expand description

Calculate the quantile values from a 1D array

§Arguments

  • array - The input 1D array
  • q - The quantile or array of quantiles to compute (between 0 and 1)
  • method - The interpolation method to use: “linear” (default), “lower”, “higher”, “midpoint”, or “nearest”

§Returns

An array containing the quantile values

§Examples

use ndarray::array;
use scirs2_core::ndarray_ext::stats::quantile;

let data = array![1.0, 3.0, 5.0, 7.0, 9.0];

// Median (50th percentile)
let median = quantile(data.view(), array![0.5].view(), Some("linear")).unwrap();
assert_eq!(median[0], 5.0);

// Multiple quantiles
let quartiles = quantile(data.view(), array![0.25, 0.5, 0.75].view(), None).unwrap();
assert_eq!(quartiles[0], 3.0);  // 25th percentile
assert_eq!(quartiles[1], 5.0);  // 50th percentile
assert_eq!(quartiles[2], 7.0);  // 75th percentile

This function is equivalent to NumPy’s np.quantile function.