histogram

histogram(x, bins=None)

Bin a sample into a histogram.

Mirrors the C# Histogram class of the Numerics library. With bins=None the bin count follows the Rice rule, ceil(2 * n**(1/3)) + 1, exactly as the C# data constructor does.

Parameters

Name Type Description Default
x array_like Observations, at least one element. required
bins int Number of bins, must be positive. None (the default) uses the Rice rule. None

Returns

Name Type Description
dict Keys lower, upper, midpoint, frequency (each :class:numpy.ndarray, one entry per bin) and statistics (a dict with mean, median, mode, sd, lower, upper, bin_width, bins).

Examples

>>> from corehydropy import histogram
>>> h = histogram([1, 2, 2.5, 3, 3.5, 4, 5, 7, 8, 9])
>>> float(h["frequency"].sum())
10.0
>>> h["statistics"]["bins"]
6.0