pygram11.histogram#
- pygram11.histogram(x, bins=10, range=None, weights=None, density=False, flow=False, cons_var=False)[source]#
Histogram data in one dimension.
- Parameters
x (array_like) – Data to histogram.
bins (int or array_like) – If int: the number of bins; if array_like: the bin edges.
range ((float, float), optional) – The minimum and maximum of the histogram axis. If
None
with integer bins, min and max of x will be used. If bins is an array this is expected to beNone
.weights (array_like, optional) – Weight variations for the elements of x. For single weight histograms the shape must be the same shape as x. For multiweight histograms the first dimension is the length of x, second dimension is the number of weights variations.
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 bins defines edges while range is also not
None
.ValueError – If the array of bin edges is not monotonically increasing.
ValueError – If x and weights have incompatible shapes.
ValueError – If multiweight histogramming is detected and weights is not a two dimensional array.
TypeError – If x or weights are unsupported types
- Returns
numpy.ndarray
– The 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.
See also
Examples
A simple fixed width histogram:
>>> rng = np.random.default_rng(123) >>> x = rng.standard_normal(2000) >>> h, __ = histogram(x, bins=20, range=(-3, 3))
And with variable width histograms and weights:
>>> w = rng.uniform(0.3, 1.1, size=x.shape) >>> h, err = histogram(x, bins=[-3, -2, -1.5, 1.5, 3.5], weights=w)