pub struct Bins<A: Ord> { /* private fields */ }
Expand description

Bins is a sorted collection of non-overlapping 1-dimensional intervals.

All intervals are left-inclusive and right-exclusive.

Example:

extern crate ndarray_stats;
extern crate noisy_float;
use ndarray_stats::histogram::{Edges, Bins};
use noisy_float::types::n64;

let edges = Edges::from(vec![n64(0.), n64(1.), n64(2.)]);
let bins = Bins::new(edges);
// first bin
assert_eq!(
    bins.index(0),
    n64(0.)..n64(1.) // n64(1.) is not included in the bin!
);
// second bin
assert_eq!(
    bins.index(1),
    n64(1.)..n64(2.)
);

Implementations

Given a collection of Edges, it returns the corresponding Bins instance.

Returns the number of bins.

Example:
extern crate ndarray_stats;
extern crate noisy_float;
use ndarray_stats::histogram::{Edges, Bins};
use noisy_float::types::n64;

let edges = Edges::from(vec![n64(0.), n64(1.), n64(2.)]);
let bins = Bins::new(edges);
assert_eq!(
    bins.len(),
    2
);

Given value, it returns:

  • Some(i), if the i-th bin in self contains value;
  • None, if value does not belong to any of the bins in self.
Example:
extern crate ndarray_stats;
use ndarray_stats::histogram::{Edges, Bins};

let edges = Edges::from(vec![0, 2, 4, 6]);
let bins = Bins::new(edges);
let value = 1;
assert_eq!(
    bins.index_of(&1),
    Some(0)
);
assert_eq!(
    bins.index(bins.index_of(&1).unwrap()),
    0..2
);

Given value, it returns:

  • Some(left_edge..right_edge), if there exists a bin in self such that left_edge <= value < right_edge;
  • None, otherwise.
Example:
extern crate ndarray_stats;
use ndarray_stats::histogram::{Edges, Bins};

let edges = Edges::from(vec![0, 2, 4, 6]);
let bins = Bins::new(edges);
assert_eq!(
    bins.range_of(&1),
    Some(0..2)
);
assert_eq!(
    bins.range_of(&10),
    None
);

Get the i-th bin.

Panics if index is out of bounds.

Example:
extern crate ndarray_stats;
use ndarray_stats::histogram::{Edges, Bins};

let edges = Edges::from(vec![1, 5, 10, 20]);
let bins = Bins::new(edges);
assert_eq!(
    bins.index(1),
    5..10
);

Trait Implementations

Returns a copy of the value. Read more
Performs copy-assignment from source. Read more
Formats the value using the given formatter. Read more
This method tests for self and other values to be equal, and is used by ==. Read more
This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

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

The resulting type after obtaining ownership.
Creates owned data from borrowed data, usually by cloning. Read more
Uses borrowed data to replace owned data, usually by cloning. Read more
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.