Struct ndarray_histogram::histogram::Histogram
source · pub struct Histogram<A: Ord + Send> { /* private fields */ }
Expand description
Histogram data structure.
Implementations§
source§impl<A: Ord + Send> Histogram<A>
impl<A: Ord + Send> Histogram<A>
sourcepub fn add_observation<S>(
&mut self,
observation: &ArrayBase<S, Ix1>
) -> Result<(), BinNotFound>where
S: Data<Elem = A>,
pub fn add_observation<S>( &mut self, observation: &ArrayBase<S, Ix1> ) -> Result<(), BinNotFound>where S: Data<Elem = A>,
Adds a single observation to the histogram.
Panics if dimensions do not match: self.ndim() != observation.len()
.
Example:
use ndarray::array;
use ndarray_histogram::histogram::{Bins, Edges, Grid, Histogram};
use noisy_float::types::n64;
let edges = Edges::from(vec![n64(-1.), n64(0.), n64(1.)]);
let bins = Bins::new(edges);
let square_grid = Grid::from(vec![bins.clone(), bins.clone()]);
let mut histogram = Histogram::new(square_grid);
let observation = array![n64(0.5), n64(0.6)];
histogram.add_observation(&observation)?;
let histogram_matrix = histogram.counts();
let expected = array![[0, 0], [0, 1],];
assert_eq!(histogram_matrix, expected.into_dyn());
sourcepub fn ndim(&self) -> usize
pub fn ndim(&self) -> usize
Returns the number of dimensions of the space the histogram is covering.
sourcepub fn counts(&self) -> ArrayViewD<'_, usize>
pub fn counts(&self) -> ArrayViewD<'_, usize>
Borrows a view on the histogram counts matrix.