Skip to content
DeepForgeby svx
All problems
MediumStatisticsst-323

Weighted Harmonic Mean

Problem

The weighted harmonic mean is sum(w_i) / sum(w_i / x_i).

Given the values and their positive weights, return the weighted harmonic mean.

Hint

Weights multiply the reciprocal contributions.

Test cases

case 1
in: [[1,2],[1,1]]
expected: 1.3333333333333333
case 2
in: [[2,4],[3,1]]
expected: 2.2857142857142856
case 3
in: [[5,10,20],[1,2,1]]
expected: 8.88888888888889
Starter codePython
def weighted_harmonic_mean(values, weights):
    # Your code here
    pass

3 test cases · run your code against them in the editor