pygram11.fix1d¶

pygram11.
fix1d
(x, bins=10, range=None, weights=None, density=False, flow=False, cons_var=False)[source]¶ Histogram data with fixed (uniform) bin widths.
 Parameters
x (numpy.ndarray) – Data to histogram.
bins (int) – The number of bins.
range ((float, float), optional) – The minimum and maximum of the histogram axis. If
None
, min and max of x will be used.weights (numpy.ndarray, optional) – The weights for each element of x. If weights are absent, the second return type will be
None
.density (bool) – Normalize histogram counts as value of PDF such that the integral over the range is unity.
flow (bool) – Include under/overflow in the first/last bins.
cons_var (bool) – If
True
, conserve the variance rather than return the standard error (square root of the variance).
 Raises
ValueError – If x and weights have incompatible shapes.
TypeError – If x or weights are unsupported types
 Returns
numpy.ndarray
– The resulting histogram bin counts.numpy.ndarray
, optional – The standard error of each bin count, \(\sqrt{\sum_i w_i^2}\). The return isNone
if weights are not used. If cons_var isTrue
, the variances are returned.
Examples
A histogram of x with 20 bins between 0 and 100:
>>> rng = np.random.default_rng(123) >>> x = rng.uniform(0, 100, size=(100,)) >>> h, __ = fix1d(x, bins=20, range=(0, 100))
When weights are absent the second return is
None
. The same data, now histogrammed with weights and over/underflow included:>>> rng = np.random.default_rng(123) >>> x = rng.uniform(0, 100, size=(100,)) >>> w = rng.uniform(0.1, 0.9, x.shape[0]) >>> h, stderr = fix1d(x, bins=20, range=(0, 100), weights=w, flow=True)