Trait ndarray_stats::Quantile1dExt
source · pub trait Quantile1dExt<A, S>where
S: Data<Elem = A>,{
fn quantile_mut<I>(&mut self, q: f64) -> Option<A>
where
A: Ord + Clone,
S: DataMut,
I: Interpolate<A>;
}
Expand description
Quantile methods for 1-D arrays.
Required Methods
sourcefn quantile_mut<I>(&mut self, q: f64) -> Option<A>where
A: Ord + Clone,
S: DataMut,
I: Interpolate<A>,
fn quantile_mut<I>(&mut self, q: f64) -> Option<A>where
A: Ord + Clone,
S: DataMut,
I: Interpolate<A>,
Return the qth quantile of the data.
q
needs to be a float between 0 and 1, bounds included.
The qth quantile for a 1-dimensional array of length N
is defined
as the element that would be indexed as (N-1)q
if the array were to be sorted
in increasing order.
If (N-1)q
is not an integer the desired quantile lies between
two data points: we return the lower, nearest, higher or interpolated
value depending on the type Interpolate
bound I
.
Some examples:
q=0.
returns the minimum;q=0.5
returns the median;q=1.
returns the maximum. (q=0
andq=1
are considered improper quantiles)
The array is shuffled in place in order to produce the required quantile without allocating a copy. No assumptions should be made on the ordering of the array elements after this computation.
Complexity (quickselect):
- average case: O(
m
); - worst case: O(
m
^2); wherem
is the number of elements in the array.
Returns None
if the array is empty.
Panics if q
is not between 0.
and 1.
(inclusive).