Struct ndarray_stats::histogram::Grid [−][src]
A Grid
is a partition of a rectangular region of an n-dimensional
space—e.g. [a0, b0) × ⋯ × [an−1,
bn−1)—into a collection of rectangular n-dimensional bins.
The grid is fully determined by its 1-dimensional projections on the
coordinate axes. For example, this is a partition that can be represented
as a Grid
struct:
+---+-------+-+
| | | |
+---+-------+-+
| | | |
| | | |
| | | |
| | | |
+---+-------+-+
while the next one can’t:
+---+-------+-+
| | | |
| +-------+-+
| | |
| | |
| | |
| | |
+---+-------+-+
Example:
use ndarray::{Array, array}; use ndarray_stats::{HistogramExt, histogram::{Histogram, Grid, GridBuilder, Edges, Bins, strategies::Auto}}; use noisy_float::types::{N64, n64}; // 1-dimensional observations, as a (n_observations, 1) 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, // specifying a strategy (Auto in this case) let grid = GridBuilder::<Auto<usize>>::from_array(&observations).unwrap().build(); let expected_grid = Grid::from(vec![Bins::new(Edges::from(vec![1, 20, 39, 58, 77, 96, 115]))]); assert_eq!(grid, expected_grid); let histogram = observations.histogram(grid); let histogram_matrix = histogram.counts(); // Bins are left inclusive, right exclusive! let expected = array![4, 3, 3, 1, 0, 1]; assert_eq!(histogram_matrix, expected.into_dyn());
Implementations
impl<A: Ord> Grid<A>
[src]
pub fn ndim(&self) -> usize
[src]
Returns n
, the number of dimensions of the region partitioned by the grid.
pub fn shape(&self) -> Vec<usize>
[src]
Returns the number of bins along each coordinate axis.
pub fn projections(&self) -> &[Bins<A>]
[src]
Returns the grid projections on the coordinate axes as a slice of immutable references.
pub fn index_of<S>(&self, point: &ArrayBase<S, Ix1>) -> Option<Vec<usize>> where
S: Data<Elem = A>,
[src]
S: Data<Elem = A>,
Returns the index of the n-dimensional bin containing the point, if one exists.
Returns None
if the point is outside the grid.
Panics if point.len()
does not equal self.ndim()
.
impl<A: Ord + Clone> Grid<A>
[src]
pub fn index(&self, index: &[usize]) -> Vec<Range<A>>
[src]
Given i=(i_0, ..., i_{n-1})
, an n
-dimensional index, it returns
I_{i_0}x...xI_{i_{n-1}}
, an n
-dimensional bin, where I_{i_j}
is
the i_j
-th interval on the j
-th projection of the grid on the coordinate axes.
Panics if at least one among (i_0, ..., i_{n-1})
is out of bounds on the respective
coordinate axis - i.e. if there exists j
such that i_j >= self.projections[j].len()
.
Trait Implementations
impl<A: Clone + Ord> Clone for Grid<A>
[src]
impl<A: Debug + Ord> Debug for Grid<A>
[src]
impl<A: Eq + Ord> Eq for Grid<A>
[src]
impl<A: Ord> From<Vec<Bins<A>, Global>> for Grid<A>
[src]
fn from(projections: Vec<Bins<A>>) -> Self
[src]
Get a Grid
instance from a Vec<Bins<A>>
.
The i
-th element in Vec<Bins<A>>
represents the 1-dimensional
projection of the bin grid on the i
-th axis.
Alternatively, a Grid
can be built directly from data using a
GridBuilder
.
impl<A: PartialEq + Ord> PartialEq<Grid<A>> for Grid<A>
[src]
impl<A: Ord> StructuralEq for Grid<A>
[src]
impl<A: Ord> StructuralPartialEq for Grid<A>
[src]
Auto Trait Implementations
impl<A> RefUnwindSafe for Grid<A> where
A: RefUnwindSafe,
A: RefUnwindSafe,
impl<A> Send for Grid<A> where
A: Send,
A: Send,
impl<A> Sync for Grid<A> where
A: Sync,
A: Sync,
impl<A> Unpin for Grid<A> where
A: Unpin,
A: Unpin,
impl<A> UnwindSafe for Grid<A> where
A: UnwindSafe,
A: UnwindSafe,
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<Q, K> Equivalent<K> for Q where
K: Borrow<Q> + ?Sized,
Q: Eq + ?Sized,
[src]
K: Borrow<Q> + ?Sized,
Q: Eq + ?Sized,
pub fn equivalent(&self, key: &K) -> bool
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
pub fn to_owned(&self) -> T
[src]
pub fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
pub fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
[src]
V: MultiLane<T>,