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 in a contributes 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 of a along the given axis) or of the same shape as a. If weights=None, then all data in a are assumed to have a weight equal to one. The only constraint on weights is that sum(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, where fraction is the fractional part of the index surrounded by i and j.

    • lower: i.

    • higher: j.

    • nearest: i or j, whichever is nearest.

    • midpoint: (i + j) / 2.

Returns

quantile – If q is a single quantile and axis=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 of a. If the input contains integers or floats smaller than float64, the output data-type is float64. Otherwise, the output data-type is the same as that of the input. If out is specified, that array is returned instead.

Return type

scalar, array