lib.utils.weighted_quantile¶
- lib.utils.weighted_quantile(x, q, weights=None, axis=None, interpolation='lower')¶
Compute the q-th quantile of the weighted data along the specified axis.
- Parameters
a (array) – Input array or object that can be converted to an array.
q (tuple, list, array) – Quantile or sequence of quantiles to compute, which must be between 0 and 1 inclusive.
weights (array, default=None) – An array of weights associated with the values in
a. Each value inacontributes to the cumulative distribution according to its associated weight. The weights array can either be 1D (in which case its length must be the size ofaalong the given axis) or of the same shape asa. Ifweights=None, then all data inaare assumed to have a weight equal to one. The only constraint onweightsis thatsum(weights)must not be 0.axis (int, tuple, default=None) – Axis or axes along which the quantiles are computed. The default is to compute the quantile(s) along a flattened version of the array.
interpolation ({'linear', 'lower', 'higher', 'midpoint', 'nearest'}, default='linear') –
This optional parameter specifies the interpolation method to use when the desired quantile lies between two data points
i < j:linear:
i + (j - i) * fraction, wherefractionis the fractional part of the index surrounded byiandj.lower:
i.higher:
j.nearest:
iorj, whichever is nearest.midpoint:
(i + j) / 2.
- Returns
quantile – If
qis a single quantile andaxis=None, then the result is a scalar. If multiple quantiles are given, first axis of the result corresponds to the quantiles. The other axes are the axes that remain after the reduction ofa. If the input contains integers or floats smaller thanfloat64, the output data-type isfloat64. Otherwise, the output data-type is the same as that of the input. Ifoutis specified, that array is returned instead.- Return type
scalar, array
Note
Inspired from https://github.com/minaskar/cronus/blob/master/cronus/plot.py.