weighted_median#

caput.algorithms.median.weighted_median(A: numpy.typing.NDArray[numpy.int_ | numpy.float64], W: numpy.typing.NDArray[numpy.int_ | numpy.float64], method: Literal['lower', 'higher', 'split'] = 'split') numpy.ndarray[numpy.floating | numpy.integer] | numpy.integer | numpy.floating[source]#

Calculate the weighted median of a set of data.

The weighted median is always calculated along the last axis.

See quantile for more information on the behaviour for some special cases.

Parameters:
Andarray

The array of data.

Wndarray

The array of weights.

method{“lower”, “higher”, “split”}

Method to use if the requested quantile is exactly between two elements. Must be one of “lower”, “higher” or “split”. Default is “split”.

Returns:
medianarray_like

The calculated median. This has the same shape as A with the last axis removed. If A was one dimensional the value returned is a scalar.