Trait ndarray_stats::QuantileExt
source · pub trait QuantileExt<A, S, D>{
// Required methods
fn argmin(&self) -> Result<D::Pattern, MinMaxError>
where A: PartialOrd;
fn argmin_skipnan(&self) -> Result<D::Pattern, EmptyInput>
where A: MaybeNan,
A::NotNan: Ord;
fn min(&self) -> Result<&A, MinMaxError>
where A: PartialOrd;
fn min_skipnan(&self) -> &A
where A: MaybeNan,
A::NotNan: Ord;
fn argmax(&self) -> Result<D::Pattern, MinMaxError>
where A: PartialOrd;
fn argmax_skipnan(&self) -> Result<D::Pattern, EmptyInput>
where A: MaybeNan,
A::NotNan: Ord;
fn max(&self) -> Result<&A, MinMaxError>
where A: PartialOrd;
fn max_skipnan(&self) -> &A
where A: MaybeNan,
A::NotNan: Ord;
fn quantile_axis_mut<I>(
&mut self,
axis: Axis,
q: N64,
interpolate: &I,
) -> Result<Array<A, D::Smaller>, QuantileError>
where D: RemoveAxis,
A: Ord + Clone,
S: DataMut,
I: Interpolate<A>;
fn quantiles_axis_mut<S2, I>(
&mut self,
axis: Axis,
qs: &ArrayBase<S2, Ix1>,
interpolate: &I,
) -> Result<Array<A, D>, QuantileError>
where D: RemoveAxis,
A: Ord + Clone,
S: DataMut,
S2: Data<Elem = N64>,
I: Interpolate<A>;
fn quantile_axis_skipnan_mut<I>(
&mut self,
axis: Axis,
q: N64,
interpolate: &I,
) -> Result<Array<A, D::Smaller>, QuantileError>
where D: RemoveAxis,
A: MaybeNan,
A::NotNan: Clone + Ord,
S: DataMut,
I: Interpolate<A::NotNan>;
fn __private__(&self, _: PrivateMarker);
}
Expand description
Quantile methods for ArrayBase
.
Required Methods§
sourcefn argmin(&self) -> Result<D::Pattern, MinMaxError>where
A: PartialOrd,
fn argmin(&self) -> Result<D::Pattern, MinMaxError>where
A: PartialOrd,
Finds the index of the minimum value of the array.
Returns Err(MinMaxError::UndefinedOrder)
if any of the pairwise
orderings tested by the function are undefined. (For example, this
occurs if there are any floating-point NaN values in the array.)
Returns Err(MinMaxError::EmptyInput)
if the array is empty.
Even if there are multiple (equal) elements that are minima, only one index is returned. (Which one is returned is unspecified and may depend on the memory layout of the array.)
§Example
use ndarray::array;
use ndarray_stats::QuantileExt;
let a = array![[1., 3., 5.],
[2., 0., 6.]];
assert_eq!(a.argmin(), Ok((1, 1)));
sourcefn argmin_skipnan(&self) -> Result<D::Pattern, EmptyInput>
fn argmin_skipnan(&self) -> Result<D::Pattern, EmptyInput>
Finds the index of the minimum value of the array skipping NaN values.
Returns Err(EmptyInput)
if the array is empty or none of the values in the array
are non-NaN values.
Even if there are multiple (equal) elements that are minima, only one index is returned. (Which one is returned is unspecified and may depend on the memory layout of the array.)
§Example
use ndarray::array;
use ndarray_stats::QuantileExt;
let a = array![[::std::f64::NAN, 3., 5.],
[2., 0., 6.]];
assert_eq!(a.argmin_skipnan(), Ok((1, 1)));
sourcefn min(&self) -> Result<&A, MinMaxError>where
A: PartialOrd,
fn min(&self) -> Result<&A, MinMaxError>where
A: PartialOrd,
Finds the elementwise minimum of the array.
Returns Err(MinMaxError::UndefinedOrder)
if any of the pairwise
orderings tested by the function are undefined. (For example, this
occurs if there are any floating-point NaN values in the array.)
Returns Err(MinMaxError::EmptyInput)
if the array is empty.
Even if there are multiple (equal) elements that are minima, only one is returned. (Which one is returned is unspecified and may depend on the memory layout of the array.)
sourcefn min_skipnan(&self) -> &A
fn min_skipnan(&self) -> &A
Finds the elementwise minimum of the array, skipping NaN values.
Even if there are multiple (equal) elements that are minima, only one is returned. (Which one is returned is unspecified and may depend on the memory layout of the array.)
Warning This method will return a NaN value if none of the values in the array are non-NaN values. Note that the NaN value might not be in the array.
sourcefn argmax(&self) -> Result<D::Pattern, MinMaxError>where
A: PartialOrd,
fn argmax(&self) -> Result<D::Pattern, MinMaxError>where
A: PartialOrd,
Finds the index of the maximum value of the array.
Returns Err(MinMaxError::UndefinedOrder)
if any of the pairwise
orderings tested by the function are undefined. (For example, this
occurs if there are any floating-point NaN values in the array.)
Returns Err(MinMaxError::EmptyInput)
if the array is empty.
Even if there are multiple (equal) elements that are maxima, only one index is returned. (Which one is returned is unspecified and may depend on the memory layout of the array.)
§Example
use ndarray::array;
use ndarray_stats::QuantileExt;
let a = array![[1., 3., 7.],
[2., 5., 6.]];
assert_eq!(a.argmax(), Ok((0, 2)));
sourcefn argmax_skipnan(&self) -> Result<D::Pattern, EmptyInput>
fn argmax_skipnan(&self) -> Result<D::Pattern, EmptyInput>
Finds the index of the maximum value of the array skipping NaN values.
Returns Err(EmptyInput)
if the array is empty or none of the values in the array
are non-NaN values.
Even if there are multiple (equal) elements that are maxima, only one index is returned. (Which one is returned is unspecified and may depend on the memory layout of the array.)
§Example
use ndarray::array;
use ndarray_stats::QuantileExt;
let a = array![[::std::f64::NAN, 3., 5.],
[2., 0., 6.]];
assert_eq!(a.argmax_skipnan(), Ok((1, 2)));
sourcefn max(&self) -> Result<&A, MinMaxError>where
A: PartialOrd,
fn max(&self) -> Result<&A, MinMaxError>where
A: PartialOrd,
Finds the elementwise maximum of the array.
Returns Err(MinMaxError::UndefinedOrder)
if any of the pairwise
orderings tested by the function are undefined. (For example, this
occurs if there are any floating-point NaN values in the array.)
Returns Err(EmptyInput)
if the array is empty.
Even if there are multiple (equal) elements that are maxima, only one is returned. (Which one is returned is unspecified and may depend on the memory layout of the array.)
sourcefn max_skipnan(&self) -> &A
fn max_skipnan(&self) -> &A
Finds the elementwise maximum of the array, skipping NaN values.
Even if there are multiple (equal) elements that are maxima, only one is returned. (Which one is returned is unspecified and may depend on the memory layout of the array.)
Warning This method will return a NaN value if none of the values in the array are non-NaN values. Note that the NaN value might not be in the array.
sourcefn quantile_axis_mut<I>(
&mut self,
axis: Axis,
q: N64,
interpolate: &I,
) -> Result<Array<A, D::Smaller>, QuantileError>
fn quantile_axis_mut<I>( &mut self, axis: Axis, q: N64, interpolate: &I, ) -> Result<Array<A, D::Smaller>, QuantileError>
Return the qth quantile of the data along the specified axis.
q
needs to be a float between 0 and 1, bounds included.
The qth quantile for a 1-dimensional lane of length N
is defined
as the element that would be indexed as (N-1)q
if the lane 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 interpolate
strategy.
Some examples:
q=0.
returns the minimum along each 1-dimensional lane;q=0.5
returns the median along each 1-dimensional lane;q=1.
returns the maximum along each 1-dimensional lane. (q=0
andq=1
are considered improper quantiles)
The array is shuffled in place along each 1-dimensional lane in order to produce the required quantile without allocating a copy of the original array. Each 1-dimensional lane is shuffled independently from the others. 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 Err(EmptyInput)
when the specified axis has length 0.
Returns Err(InvalidQuantile(q))
if q
is not between 0.
and 1.
(inclusive).
Panics if axis
is out of bounds.
sourcefn quantiles_axis_mut<S2, I>(
&mut self,
axis: Axis,
qs: &ArrayBase<S2, Ix1>,
interpolate: &I,
) -> Result<Array<A, D>, QuantileError>
fn quantiles_axis_mut<S2, I>( &mut self, axis: Axis, qs: &ArrayBase<S2, Ix1>, interpolate: &I, ) -> Result<Array<A, D>, QuantileError>
A bulk version of quantile_axis_mut
, optimized to retrieve multiple
quantiles at once.
Returns an Array
, where subviews along axis
of the array correspond
to the elements of qs
.
See quantile_axis_mut
for additional details on quantiles and the algorithm
used to retrieve them.
Returns Err(EmptyInput)
when the specified axis has length 0.
Returns Err(InvalidQuantile(q))
if any q
in qs
is not between 0.
and 1.
(inclusive).
Panics if axis
is out of bounds.
§Example
use ndarray::{array, aview1, Axis};
use ndarray_stats::{QuantileExt, interpolate::Nearest};
use noisy_float::types::n64;
let mut data = array![[3, 4, 5], [6, 7, 8]];
let axis = Axis(1);
let qs = &[n64(0.3), n64(0.7)];
let quantiles = data.quantiles_axis_mut(axis, &aview1(qs), &Nearest).unwrap();
for (&q, quantile) in qs.iter().zip(quantiles.axis_iter(axis)) {
assert_eq!(quantile, data.quantile_axis_mut(axis, q, &Nearest).unwrap());
}
sourcefn quantile_axis_skipnan_mut<I>(
&mut self,
axis: Axis,
q: N64,
interpolate: &I,
) -> Result<Array<A, D::Smaller>, QuantileError>
fn quantile_axis_skipnan_mut<I>( &mut self, axis: Axis, q: N64, interpolate: &I, ) -> Result<Array<A, D::Smaller>, QuantileError>
Return the q
th quantile of the data along the specified axis, skipping NaN values.
See quantile_axis_mut
for details.
sourcefn __private__(&self, _: PrivateMarker)
fn __private__(&self, _: PrivateMarker)
This method makes this trait impossible to implement outside of
ndarray-stats
so that we can freely add new methods, etc., to
this trait without breaking changes.
We don’t anticipate any other crates needing to implement this trait, but if you do have such a use-case, please let us know.
Warning This method is not considered part of the public API, and client code should not rely on it being present. It may be removed in a non-breaking release.