histogram

Function histogram 

Source
pub fn histogram<T>(
    array: ArrayView<'_, T, Ix1>,
    bins: usize,
    range: Option<(T, T)>,
    weights: Option<ArrayView<'_, T, Ix1>>,
) -> HistogramResult<T>
where T: Clone + Float + FromPrimitive,
Expand description

Calculate a histogram of data

§Arguments

  • array - The input 1D array
  • bins - The number of bins
  • range - Optional tuple (min, max) to use. If None, the range is based on data
  • weights - Optional array of weights for each data point

§Returns

A tuple containing (histogram, bin_edges)

§Examples

use ndarray::array;
use scirs2_core::ndarray_ext::stats::histogram;

let data = array![0.1, 0.5, 1.1, 1.5, 2.2, 2.9, 3.1, 3.8, 4.1, 4.9];
let (hist, bin_edges) = histogram(data.view(), 5, None, None).unwrap();

assert_eq!(hist.len(), 5);
assert_eq!(bin_edges.len(), 6);