Skip to content
DeepForgeby svx
All problems
EasyStatisticsst-322

Harmonic Mean of Rates

Problem

For rates that combine as reciprocals, such as speeds, the harmonic mean is n / sum_i (1 / x_i).

Given the rate list, return the harmonic mean.

Hint

Invert, average, and invert again.

Test cases

case 1
in: [[1,2]]
expected: 1.3333333333333333
case 2
in: [[2,4,8]]
expected: 3.4285714285714284
case 3
in: [[10,10]]
expected: 10
Starter codePython
def harmonic_mean_of_rates(rates):
    # Your code here
    pass

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