API Reference

Summary

histogram(x[, bins, range, weights, flow])

Calculate the histogram for the data x.

mwv_histogram(x, weights[, bins, range, flow])

Histogram the same data but with multiple weight variations.

Functions

humba.histogram(x: numpy.ndarray, bins: int = 10, range: Tuple[float, float] = (0, 10), weights: Optional[numpy.ndarray] = None, flow: bool = False) → Tuple[numpy.ndarray, Optional[numpy.ndarray], numpy.ndarray][source]

Calculate the histogram for the data x.

Parameters
  • x (numpy.ndarray) – data to histogram

  • bins (int) – number of bins

  • range ((float, float)) – axis range

  • weights (numpy.ndarray, optional) – array of weights for x

  • flow (bool) – include over and underflow content in first and last bins

Returns

Notes

If the dtype of the weights is not the same as x, then it is converted to the dtype of x.

Examples

>>> import numpy as np
>>> from humba import histogram
>>> x = np.random.randn(100000)
>>> w = np.random.uniform(0.4, 0.5, x.shape[0])
>>> hist1, _, edges = humba.histogram(x, bins=50, range=(-5, 5))
>>> hist2, _, edges = humba.histogram(x, bins=50, range=(-5, 5), flow=True)
>>> hist3, error, edges = histogram(x, bins=50, range=(-5, 5), weights=w)
>>> hist4, error, edges = histogram(x, bins=50, range=(-3, 3), weights=w, flow=True)
humba.mwv_histogram(x: numpy.ndarray, weights: numpy.ndarray, bins: int = 10, range: Tuple[float, float] = (0, 10), flow: bool = False) → Tuple[numpy.ndarray, numpy.ndarray, numpy.ndarray][source]

Histogram the same data but with multiple weight variations.

Parameters
  • x (numpy.ndarray) – data to histogram

  • weights (numpy.ndarray, optional) – multidimensional array of weights for x the first element of the shape attribute must be equal to the length of x.

  • bins (int) – number of bins

  • range ((float, float)) – axis range

  • flow (bool) – include over and underflow content in first and last bins

Returns

  • count (numpy.ndarray) – The values of the histograms calculated from the weights Shape will be (bins, weights.shape[0])

  • error (numpy.ndarray) – The poission uncertainty on the bin heights (shape will be the same as count.

  • edges (numpy.ndarray) – The bin edges

Notes

If x is not the same dtype as weights, then it is converted to the dtype of weights (for multi weight histograms we expect the weights array to be larger than the data array so we prefer to cast the smaller chunk of data).