pyinterp.Histogram2DFloat32.quantile

pyinterp.Histogram2DFloat32.quantile#

Histogram2DFloat32.quantile(self, q: float) numpy.ndarray[dtype=float32, shape=(*, *), order='F']#

Compute the specified quantile for each bin.

Uses the TDigest algorithm to estimate quantiles with high accuracy, particularly at the tails of the distribution.

Parameters:

q – Quantile to compute, in the range [0, 1]. For example: - 0.0 returns the minimum - 0.25 returns the 25th percentile (Q1) - 0.5 returns the median - 0.75 returns the 75th percentile (Q3) - 1.0 returns the maximum

Returns:

2D array containing the quantile value for each bin. Bins with no data return NaN.

Raises:

ValueError – If q is not in the range [0, 1].

Examples

>>> hist = pyinterp.Histogram2D(x_axis, y_axis)
>>> hist.push(x_data, y_data, z_data)

Compute various percentiles

>>> min_grid = hist.quantile(0.0)
>>> q1_grid = hist.quantile(0.25)
>>> median_grid = hist.quantile(0.5)
>>> q3_grid = hist.quantile(0.75)
>>> max_grid = hist.quantile(1.0)

Compute 95th percentile

>>> p95 = hist.quantile(0.95)