Struct ndarray_stats::histogram::Histogram

source ·
pub struct Histogram<A: Ord> { /* private fields */ }
Expand description

Histogram data structure.

Implementations§

source§

impl<A: Ord> Histogram<A>

source

pub fn new(grid: Grid<A>) -> Self

Returns a new instance of Histogram given a Grid.

source

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_stats::histogram::{Edges, Bins, Histogram, Grid};
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());
source

pub fn ndim(&self) -> usize

Returns the number of dimensions of the space the histogram is covering.

source

pub fn counts(&self) -> ArrayViewD<'_, usize>

Borrows a view on the histogram counts matrix.

source

pub fn grid(&self) -> &Grid<A>

Borrows an immutable reference to the histogram grid.

Auto Trait Implementations§

§

impl<A> Freeze for Histogram<A>

§

impl<A> RefUnwindSafe for Histogram<A>
where A: RefUnwindSafe,

§

impl<A> Send for Histogram<A>
where A: Send,

§

impl<A> Sync for Histogram<A>
where A: Sync,

§

impl<A> Unpin for Histogram<A>
where A: Unpin,

§

impl<A> UnwindSafe for Histogram<A>
where A: UnwindSafe,

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> IntoEither for T

source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

source§

fn vzip(self) -> V