stats::axis
Statistics along one axis of an array: each lane along axis is
reduced to one value, giving an array of one rank less (NumPy's
axis= argument). Every function throws InvalidArgument for an
axis past the rank.
Functions
meanSource
pub fn mean<const N: usize>(a: Array<f64, N>, axis: usize) throws (StatsError) -> Array<f64, { N - 1 }> The mean of each lane along axis.
use core::array::Matrix;
let m: Matrix<f64> = [[1, 2, 3], [4, 5, 6]];
assert((try stats::axis::mean(m, 0)).to_list() == [2.5, 3.5, 4.5]);
assert((try stats::axis::mean(m, 1)).to_list() == [2.0, 5.0]);
sumSource
pub fn sum<const N: usize>(a: Array<f64, N>, axis: usize) throws (StatsError) -> Array<f64, { N - 1 }> The sum of each lane along axis (pairwise).
use core::array::Matrix;
let m: Matrix<f64> = [[1, 2, 9], [4, 6, 8]];
assert((try stats::axis::sum(m, 1)).to_list() == [12.0, 18.0]);
varSource
pub fn var<const N: usize>(a: Array<f64, N>, axis: usize, ddof: usize = 0) throws (StatsError) -> Array<f64, { N - 1 }> The variance of each lane along axis, dividing by n - ddof.
use core::array::Matrix;
let m: Matrix<f64> = [[1, 2], [3, 6]];
assert((try stats::axis::var(m, 0, 1)).to_list() == [2.0, 8.0]);
stdSource
pub fn std<const N: usize>(a: Array<f64, N>, axis: usize, ddof: usize = 0) throws (StatsError) -> Array<f64, { N - 1 }> The standard deviation of each lane along axis.
use core::array::Matrix;
let m: Matrix<f64> = [[1, 2, 9], [4, 6, 8]];
assert((try stats::axis::std(m, 0))[0] == 1.5);
minSource
pub fn min<const N: usize>(a: Array<f64, N>, axis: usize) throws (StatsError) -> Array<f64, { N - 1 }> The smallest value of each lane along axis.
use core::array::Matrix;
let m: Matrix<f64> = [[1, 2, 9], [4, 6, 8]];
assert((try stats::axis::min(m, 1)).to_list() == [1.0, 4.0]);
maxSource
pub fn max<const N: usize>(a: Array<f64, N>, axis: usize) throws (StatsError) -> Array<f64, { N - 1 }> The largest value of each lane along axis.
use core::array::Matrix;
let m: Matrix<f64> = [[1, 2, 9], [4, 6, 8]];
assert((try stats::axis::max(m, 0)).to_list() == [4.0, 6.0, 9.0]);
medianSource
pub fn median<const N: usize>(a: Array<f64, N>, axis: usize) throws (StatsError) -> Array<f64, { N - 1 }> The median of each lane along axis.
use core::array::Matrix;
let m: Matrix<f64> = [[3, 1, 2], [9, 7, 8]];
assert((try stats::axis::median(m, 1)).to_list() == [2.0, 8.0]);
quantileSource
pub fn quantile<const N: usize>(a: Array<f64, N>, axis: usize, q: f64, method: QuantileMethod = QuantileMethod::Linear) throws (StatsError) -> Array<f64, { N - 1 }> The q-quantile of each lane along axis, by method.
use core::array::Matrix;
let m: Matrix<f64> = [[1, 2, 9], [4, 6, 8]];
assert((try stats::axis::quantile(m, 0, 0.25)).to_list() == [1.75, 3.0, 8.25]);
skewSource
pub fn skew<const N: usize>(a: Array<f64, N>, axis: usize, bias: bool = true) throws (StatsError) -> Array<f64, { N - 1 }> The skewness of each lane along axis (see stats::skew).
use core::array::Matrix;
let m: Matrix<f64> = [[1, 2, 9], [4, 6, 8]];
assert((try stats::axis::skew(m, 1))[1] == 0.0);
kurtosisSource
pub fn kurtosis<const N: usize>(a: Array<f64, N>, axis: usize, fisher: bool = true, bias: bool = true) throws (StatsError) -> Array<f64, { N - 1 }> The kurtosis of each lane along axis (see stats::kurtosis).
use core::array::Matrix;
let m: Matrix<f64> = [[1, 2, 3, 4, 5], [2, 4, 6, 8, 10]];
let k = try stats::axis::kurtosis(m, 1);
assert((k[0] + 1.3).abs() < 1e-14 && (k[1] + 1.3).abs() < 1e-14);
applySource
pub fn apply<const N: usize>(a: Array<f64, N>, axis: usize, f: fn(Vector<f64>) -> f64) throws (StatsError) -> Array<f64, { N - 1 }> f of each lane along axis, the lane as a vector: any statistic
of one sample along an axis.
use core::array::{Matrix, Vector};
let m: Matrix<f64> = [[1, 5], [2, 9], [3, 1]];
let r = try stats::axis::apply(m, 0, |x: Vector<f64>| -> f64 { stats::range(x) });
assert(r.to_list() == [2.0, 8.0]);