Histogramming: pygram11 Specific

pygram11.fix1d(x, bins=10, range=None, weights=None, density=False, omp='auto')[source]

histogram x with fixed (uniform) binning over a range [xmin, xmax).

Parameters:
  • x (array_like) – data to histogram
  • bins (int or str, optional) – number of bins or str
  • range ((float, float), optional) – axis limits to histogram over
  • weights (array_like, optional) – weight for each element of x.
  • density (bool) – normalize histogram bins as value of PDF such that the integral over the range is 1.
  • omp (bool or str) – if True, use OpenMP if available; if “auto” (and OpenMP is available), enables OpenMP if len(x) > 10^4
Returns:

  • numpy.ndarray – bin counts (heights)
  • numpy.ndarray – square root of the sum of weights squared (only if weights is not None)

Examples

A histogram of x with 20 bins between 0 and 100, and weighted.

>>> h = fix1d(x, bins=20, range=(0, 100))

The same data, now histogrammed weighted & accelerated with OpenMP.

>>> h, h_err = fix1d(x, bins=20, range=(0, 100), omp=True)
pygram11.var1d(x, bins, weights=None, density=False, omp='auto')[source]

histogram x with variable (non-uniform) binning over a range [bins[0], bins[-1]).

Parameters:
  • x (array_like) – data to histogram
  • bins (array_like) – bin edges
  • weights (array_like, optional) – weight for each element of x
  • density (bool) – normalize histogram bins as value of PDF such that the integral over the range is 1.
  • omp (bool or str) – if True, use OpenMP if available; if “auto” (and OpenMP is available), enables OpenMP if len(x) > 10^3
Returns:

Examples

A histogram of x where the edges are defined by the list [1, 5, 10, 12]:

>>> h, w = var1d(x, [1, 5, 10, 12])

The same data, now weighted and accelerated with OpenMP:

>>> h = var1d(x, [1, 5, 10, 12], weights=w, omp=True)
pygram11.fix2d(x, y, bins=10, range=None, weights=None, omp=False)[source]

histogram the x, y data with fixed (uniform) binning in two dimensions over the ranges [xmin, xmax), [ymin, ymax).

Parameters:
  • x (array_like) – first entries in data pairs to histogram
  • y (array_like) – second entries in data pairs to histogram
  • bins (int or iterable) – if int, both dimensions will have that many bins, if iterable, the number of bins for each dimension
  • range (iterable, optional) – axis limits to histogram over in the form [(xmin, xmax), (ymin, ymax)]
  • weights (array_like, optional) – weight for each \((x_i, y_i)\) pair.
  • omp (bool) – use OpenMP if available
Returns:

Examples

A histogram of (x, y) with 20 bins between 0 and 100 in the x dimention and 10 bins between 0 and 50 in the y dimension.

>>> h = fix2d(x, y, bins=(20, 10), range=((0, 100), (0, 50)))

The same data, now histogrammed weighted (via w) & accelerated with OpenMP.

>>> h, sw2 = fix2d(x, y, bins=(20, 10), range=((0, 100), (0, 50)),
...                weights=w, omp=True)
pygram11.var2d(x, y, xbins, ybins, weights=None, omp=False)[source]

histogram the x and y data with variable width binning in two dimensions over the range [xbins[0], xbins[-1]), [ybins[0], ybins[-1])

Parameters:
  • x (array_like) – first entries in the data pairs to histogram
  • y (array_like) – second entries in the data pairs to histogram
  • xbins (array_like) – bin edges for the x dimension
  • ybins (array_like) – bin edges for the y dimension
  • weights (array_like, optional) – weights for each \((x_i, y_i)\) pair.
  • omp (bool) – use OpenMP if available
Returns:

Examples

A histogram of (x, y) where the edges are defined by a numpy.logspace() in both dimensions, accelerated with OpenMP.

>>> bins = numpy.logspace(0.1, 1.0, 10, endpoint=True)
>>> h = var2d(x, y, bins, bins, omp=True)