def weighted_median(values, weights):
if len(values) == <NUM_LIT:1>:<EOL><INDENT>return values[<NUM_LIT:0>]<EOL><DEDENT>if len(values) == <NUM_LIT:0>:<EOL><INDENT>raise ValueError('<STR_LIT>')<EOL><DEDENT>values = [float(value) for value in values]<EOL>indices_sorted = np.argsort(values)<EOL>values = [values[ind] for ind in indices_sorted]<EOL>weights = [weights[ind] for ind in indices_sorted]<EOL>total_weight = sum(weights)<EOL>below_weight = <NUM_LIT:0><EOL>i = -<NUM_LIT:1><EOL>while below_weight < total_weight / <NUM_LIT:2>:<EOL><INDENT>i += <NUM_LIT:1><EOL>below_weight += weights[i]<EOL><DEDENT>return values[i]<EOL>
Returns element such that sum of weights below and above are (roughly) equal

:param values: Values whose median is sought
:type values: List of reals
:param weights: Weights of each value
:type weights: List of positive reals
:return: value of weighted median
:rtype: Real