scipy.stats.hmean(array, axis=0, dtype=None) calculates the harmonic mean of the array elements along the specified axis of the array (list in python).
It’s formula –
array: Input array or object having the elements to calculate the harmonic mean.
axis: Axis along which the mean is to be computed. By default axis = 0
dtype: Optional. It sets the type of returned element.
Returns : Harmonic mean of the array elements based on the set parameters.
Harmonic Mean is : 2.18918918919
Code #2: With multi-dimensional data
Harmonic Mean is : [ 2.21052632 4.36363636 6.04195804] Harmonic Mean is with default axis = 0 : [ 2.21052632 4.36363636 6.04195804] Harmonic Mean is with default axis = 1 : [ 2.18918919 4. 4.66666667 4.8 ]
Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.
To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course. And to begin with your Machine Learning Journey, join the Machine Learning – Basic Level Course