Struct ndarray_stats::histogram::GridBuilder
source · [−]pub struct GridBuilder<B: BinsBuildingStrategy> { /* private fields */ }
Expand description
A builder used to create Grid
instances for histogram
computations.
Examples
Basic usage, creating a Grid
with some observations and a given strategy
:
use ndarray::Array;
use ndarray_stats::histogram::{strategies::Auto, Bins, Edges, Grid, GridBuilder};
// 1-dimensional observations, as a (n_observations, n_dimension) 2-d matrix
let observations = Array::from_shape_vec(
(12, 1),
vec![1, 4, 5, 2, 100, 20, 50, 65, 27, 40, 45, 23],
).unwrap();
// The optimal grid layout is inferred from the data, given a chosen strategy, Auto in this case
let grid = GridBuilder::<Auto<usize>>::from_array(&observations).unwrap().build();
// Equivalently, build a Grid directly
let expected_grid = Grid::from(vec![Bins::new(Edges::from(vec![1, 20, 39, 58, 77, 96, 115]))]);
assert_eq!(grid, expected_grid);
Implementations
sourceimpl<A, B> GridBuilder<B> where
A: Ord,
B: BinsBuildingStrategy<Elem = A>,
impl<A, B> GridBuilder<B> where
A: Ord,
B: BinsBuildingStrategy<Elem = A>,
sourcepub fn from_array<S>(array: &ArrayBase<S, Ix2>) -> Result<Self, BinsBuildError> where
S: Data<Elem = A>,
pub fn from_array<S>(array: &ArrayBase<S, Ix2>) -> Result<Self, BinsBuildError> where
S: Data<Elem = A>,
Returns a GridBuilder
for building a Grid
with a given strategy
and some
observations in a 2-dimensionalarray with shape (n_observations, n_dimension)
.
Errors
It returns BinsBuildError
if it is not possible to build a Grid
given
the observed data according to the chosen strategy
.
Examples
See Trait-level examples for basic usage.
Auto Trait Implementations
impl<B> RefUnwindSafe for GridBuilder<B> where
B: RefUnwindSafe,
impl<B> Send for GridBuilder<B> where
B: Send,
impl<B> Sync for GridBuilder<B> where
B: Sync,
impl<B> Unpin for GridBuilder<B> where
B: Unpin,
impl<B> UnwindSafe for GridBuilder<B> where
B: UnwindSafe,
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more