pygram11.fix1d¶
-
pygram11.
fix1d
(x, bins=10, range=None, weights=None, density=False, flow=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 ofx
will be used.weights (numpy.ndarray, optional) – The weights for each element of
x
. If weights are absent, the second return type will beNone
.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.
- Raises
ValueError – If
x
andweights
have incompatible shapes.TypeError – If
x
orweights
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.
Examples
A histogram of
x
with 20 bins between 0 and 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) >>> w = rng.uniform(0.1, 0.9, x.shape[0])) >>> h, stderr = fix1d(x, bins=20, range=(0, 100), weights=w, flow=True)