def harmonic_mean(data):
 if (iter(data) is data):
  data = list(data)
 errmsg = 'harmonic mean does not support negative values'
 n = len(data)
 if (n < 1):
  raise StatisticsError('harmonic_mean requires at least one data point')
 elif (n == 1):
  x = data[0]
  if isinstance(x, (numbers.Real, Decimal)):
   if (x < 0):
    raise StatisticsError(errmsg)
   return x
  else:
   raise TypeError('unsupported type')
 try:
  (T, total, count) = _sum(((1 / x) for x in _fail_neg(data, errmsg)))
 except ZeroDivisionError:
  return 0
 assert (count == n)
 return _convert((n / total), T)

def harmonic_mean ( data ) : if ( iter ( data ) is data ) : data = list ( data ) errmsg = 'harmonic mean does not support negative values' n = len ( data ) if ( n < 1 ) : raise StatisticsError ( 'harmonic_mean requires at least one data point' ) elif ( n == 1 ) : x = data [ 0 ] if isinstance ( x , ( numbers . Real , Decimal ) ) : if ( x < 0 ) : raise StatisticsError ( errmsg ) return x else : raise TypeError ( 'unsupported type' ) try : ( T , total , count ) = _sum ( ( ( 1 / x ) for x in _fail_neg ( data , errmsg ) ) ) except ZeroDivisionError : return 0 assert ( count == n ) return _convert ( ( n / total ) , T )
return the harmonic mean of data .