Let’s see how to calculate harmonic mean in Python.
To calculate harmonic average we need to import statistics module.
Python harmonic mean
Luckily, there is a dedicated function in statistics module to calculate harmonic mean.
import statistics as s x = [1, 5, 7, 8, 43, 6] harmonic_mean = s.harmonic_mean(x) print("Harmonic mean equals: " + str(round(harmonic_mean, 2)))