`harmonic_mean()`

function is from Standard statistics library of Python Programming Language. The basic purpose of this function is to calculate the simple Harmonic Mean of given data. The given data will always be in the form of sequence or iterator.

The Harmonic Mean is sometimes called Subcontrary Mean; the Harmonic Mean is also representing the central location of data. It is mostly used when given quantities are rates and ratios.

Following is the statistical formula of the Harmonic Mean.

Harmonic Mean Formula:

x

As you can clearly see in the formula that Harmonic Mean is the reciprocal of the Arithmetic Mean of the reciprocals of the given data.

_{1}, x_{2}, x_{3}… must be greater than Zero.As you can clearly see in the formula that Harmonic Mean is the reciprocal of the Arithmetic Mean of the reciprocals of the given data.

## Syntax of `harmonic_mean()`

Function in Python

The syntax of `harmonic_mean()`

function in Python is as follows:

`statistics.harmonic_mean(data)`

Note:

- This function is new in Python 3.6.
- Harmonic Mean doesn’t support negative values in list, tuple or any iterator.

## Parameters of `harmonic_mean()`

Function in Python

`data`

– This parameter can be any sequence or iterator (list, tuple)Note: If data in iterator is empty, `harmonic_mean()`

function raise a `StatisticsError`

## Return Value of `harmonic_mean()`

in Python

Return value of

`harmonic_mean()`

is a floating point number after calculating the Harmonic Mean of given data in a sequence or iterator (lists, tuples)

`harmonic_mean()`

Function Examples in Python

1 2 3 4 5 6 7 | # import statistics library import statistics print(statistics.harmonic_mean([1.0,2.7,3.9,5.8])) data = list([1,2,3,4,5,6,7,8,9]) print(statistics.harmonic_mean(data)) |

Output of

`harmonic_mean()`

Function in Python

2.223217210876925

3.1813718614111375