def hmean(a, axis=0, dtype=None):
 if (not isinstance(a, np.ndarray)):
  a = np.array(a, dtype=dtype)
 if np.all((a > 0)):
  if isinstance(a, np.ma.MaskedArray):
   size = a.count(axis)
  elif (axis is None):
   a = a.ravel()
   size = a.shape[0]
  else:
   size = a.shape[axis]
  return (size / np.sum((1.0 / a), axis=axis, dtype=dtype))
 else:
  raise ValueError('Harmonic mean only defined if all elements greater than zero')

def hmean ( a , axis = 0 , dtype = None ) : if ( not isinstance ( a , np . ndarray ) ) : a = np . array ( a , dtype = dtype ) if np . all ( ( a > 0 ) ) : if isinstance ( a , np . ma . MaskedArray ) : size = a . count ( axis ) elif ( axis is None ) : a = a . ravel ( ) size = a . shape [ 0 ] else : size = a . shape [ axis ] return ( size / np . sum ( ( 1.0 / a ) , axis = axis , dtype = dtype ) ) else : raise ValueError ( 'Harmonic mean only defined if all elements greater than zero' )
returns the harmonic mean of the given list of values .