Histogramming: pygram11 Specific

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

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

Parameters
  • x (array_like) – data to histogram

  • bins (int) – number of bins

  • 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.

  • flow (bool) – if True the under and overflow bin contents are added to the first and last bins, respectively

  • omp (bool or str) – if True, use OpenMP if available; if “auto” (and OpenMP is available), enables OpenMP if len(x) > 10^4

Returns

Examples

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

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

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

>>> w = np.abs(np.random.randn(x.shape[0]))
>>> h, h_err = fix1d(x, bins=20, range=(0, 100), weights=w, omp=True)
pygram11.fix1dmw(x, weights, bins=10, range=None, flow=False, omp='auto')[source]

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

Parameters
  • x (array_like) – data to histogram

  • weights (array_like) – weight variations for the elements of x, first dimension is the shape of x, second dimension is the number of weights.

  • bins (int) – number of bins

  • range ((float, float), optional) – axis limits to histogram over

  • flow (bool) – if True the under and overflow bin contents are added to the first and last bins, respectively

  • 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) for each variation (shape == [n_bins, n_weight_variations])

  • numpy.ndarray – Poisson uncertainty on counts, shape == [n_bins, n_weight_variations],

Examples

Multiple histograms of x with 50 bins between 0 and 100; using 20 different weight variations:

>>> x = np.random.randn(10000)
>>> twenty_weights = np.random.rand(x.shape[0], 20)
>>> h, err = fix1dmw(x, w, bins=50, range=(-3, 3), omp=True)

h and err are now shape (50, 20). Each column represents the histogram of the data with the respective weight.

pygram11.var1d(x, bins, weights=None, density=False, flow=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.

  • flow (bool) – if True the under and overflow bin contents are added to the first and last bins, respectively

  • 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, __ = var1d(x, [1, 5, 10, 12])

The same data, now weighted and accelerated with OpenMP:

>>> h, err = var1d(x, [1, 5, 10, 12], weights=w, omp=True)
pygram11.var1dmw(x, weights, bins, flow=False, omp='auto')[source]

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

Parameters
  • x (array_like) – data to histogram

  • weights (array_like) – weight variations for the elements of x, first dimension is the shape of x, second dimension is the number of weights.

  • bins (int or str, optional) – number of bins or str

  • flow (bool) – if True the under and overflow bin contents are added to the first and last bins, respectively

  • 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) for each variation (shape == [n_bins, n_weight_variations])

  • numpy.ndarray – Poisson uncertainty on counts, shape == [n_bins, n_weight_variations]

Examples

Multiple histograms of x (with 9 variable width bins); using 20 different weight variations (also shifting under and overflow contents):

>>> x = np.random.randn(10000)
>>> bins = [-2, -1.5, -1.2, -1, -0.8, 0, 1.2, 1.5, 3.0]
>>> twenty_weights = np.random.rand(x.shape[0], 20)
>>> h, err = fix1dmw(x, w, bins, flow, True, omp=True)

h and err are now shape (9, 20). Each column represents the histogram of the data with the respective weight.

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, err = 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)