harmonic_mean() method का use दिए गए numeric data set harmonic mean (central location) calculate करता है।

Harmonic mean = data के reciprocals के arithmetic mean का reciprocal.

for example - अगर हमरे pass 4 values 2,3,4,5: हैं तो इनका harmonic mean : 4/(2/4 + 3/4 + 4/4 + 5/4) होगा।

harmonic_mean Syntax

statistics.harmonic_mean(data)

Parameters

  1. data | required : data जिसका हमें harmonic_mean calculate करना है , आप इसमें numeric values की list या कोई भी iterator (list, tuple, set) pass कर सकते हैं।

    ध्यान रहे कोई भी negative value नहीं होनी चाहिए।

  2. Return value : pass की गयी values के according float value return होती है।

harmonic_mean() Example

Copy Fullscreen Close Fullscreen Run
# Import statistics module.
# Import statistics module.
import statistics

#pass data in list.
print('Calculate using list')
print(statistics.harmonic_mean([23,34,546,67]))
print(statistics.harmonic_mean([2,3,4,5]))

#pass data in tuple.
print('Calculate using tuple')
print(statistics.harmonic_mean((23,34,546,67)))
print(statistics.harmonic_mean((2,3,4,5)))

#pass data in set.
print('Calculate using set')
print(statistics.harmonic_mean({23,34,546,67}))
print(statistics.harmonic_mean({2,3,4,5}))
Output
C:\Users\Rahulkumar\Desktop\python>python test.py
Calculate using list
44.61950135306917
3.116883116883117
Calculate using tuple
44.61950135306917
3.116883116883117
Calculate using set
44.61950135306917
3.116883116883117

Related Topics :

Rahul Kumar

Rahul Kumar

Hi ! I'm Rahul Kumar Rajput founder of learnhindituts.com. I'm a software developer having more than 4 years of experience. I love to talk about programming as well as writing technical tutorials and blogs that can help to others. I'm here to help you navigate the coding cosmos and turn your ideas into reality, keep coding, keep learning :)

Get connected with me. :) LinkedIn Twitter Instagram Facebook

b2eprogrammers