Trait ndarray_stats::HistogramExt[][src]

pub trait HistogramExt<A, S> where
    S: Data<Elem = A>, 
{ fn histogram(&self, grid: Grid<A>) -> Histogram<A>
    where
        A: Ord
;
fn __private__(&self, _: PrivateMarker); }

Extension trait for ArrayBase providing methods to compute histograms.

Required methods

fn histogram(&self, grid: Grid<A>) -> Histogram<A> where
    A: Ord
[src]

Returns the histogram for a 2-dimensional array of points M.

Let (n, d) be the shape of M:

  • n is the number of points;
  • d is the number of dimensions of the space those points belong to. It follows that every column in M is a d-dimensional point.

For example: a (3, 4) matrix M is a collection of 3 points in a 4-dimensional space.

Important: points outside the grid are ignored!

Panics if d is different from grid.ndim().

Example:

use ndarray::array;
use ndarray_stats::{
    HistogramExt,
    histogram::{
        Histogram, Grid, GridBuilder,
        Edges, Bins,
        strategies::Sqrt},
};
use noisy_float::types::{N64, n64};

let observations = array![
    [n64(1.), n64(0.5)],
    [n64(-0.5), n64(1.)],
    [n64(-1.), n64(-0.5)],
    [n64(0.5), n64(-1.)]
];
let grid = GridBuilder::<Sqrt<N64>>::from_array(&observations).unwrap().build();
let expected_grid = Grid::from(
    vec![
        Bins::new(Edges::from(vec![n64(-1.), n64(0.), n64(1.), n64(2.)])),
        Bins::new(Edges::from(vec![n64(-1.), n64(0.), n64(1.), n64(2.)])),
    ]
);
assert_eq!(grid, expected_grid);

let histogram = observations.histogram(grid);

let histogram_matrix = histogram.counts();
// Bins are left inclusive, right exclusive!
let expected = array![
    [1, 0, 1],
    [1, 0, 0],
    [0, 1, 0],
];
assert_eq!(histogram_matrix, expected.into_dyn());

fn __private__(&self, _: PrivateMarker)[src]

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.

Loading content...

Implementations on Foreign Types

impl<A, S> HistogramExt<A, S> for ArrayBase<S, Ix2> where
    S: Data<Elem = A>,
    A: Ord
[src]

Loading content...

Implementors

Loading content...