parameters: (data)
return_statement: return _convert(n/total, T)
docstring: Return the harmonic mean of data.
  
      The harmonic mean, sometimes called the subcontrary mean, is the
      reciprocal of the arithmetic mean of the reciprocals of the data,
      and is often appropriate when averaging quantities which are rates
      or ratios, for example speeds. Example:
  
      Suppose an investor purchases an equal value of shares in each of
      three companies, with P/E (price/earning) ratios of 2.5, 3 and 10.
      What is the average P/E ratio for the investor's portfolio?
  
      >>> harmonic_mean([2.5, 3, 10])  # For an equal investment portfolio.
      3.6
  
      Using the arithmetic mean would give an average of about 5.167, which
      is too high.
  
      If ``data`` is empty, or any element is less than zero,
      ``harmonic_mean`` will raise ``StatisticsError``.
docstring_summary: Return the harmonic mean of data.
docstring_tokens: Return the harmonic mean of data .
function: def harmonic_mean(data):
      """Return the harmonic mean of data.
  
      The harmonic mean, sometimes called the subcontrary mean, is the
      reciprocal of the arithmetic mean of the reciprocals of the data,
      and is often appropriate when averaging quantities which are rates
      or ratios, for example speeds. Example:
  
      Suppose an investor purchases an equal value of shares in each of
      three companies, with P/E (price/earning) ratios of 2.5, 3 and 10.
      What is the average P/E ratio for the investor's portfolio?
  
      >>> harmonic_mean([2.5, 3, 10])  # For an equal investment portfolio.
      3.6
  
      Using the arithmetic mean would give an average of about 5.167, which
      is too high.
  
      If ``data`` is empty, or any element is less than zero,
      ``harmonic_mean`` will raise ``StatisticsError``.
      """
      # For a justification for using harmonic mean for P/E ratios, see
      # http://fixthepitch.pellucid.com/comps-analysis-the-missing-harmony-of-summary-statistics/
      # http://papers.ssrn.com/sol3/papers.cfm?abstract_id=2621087
      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)
function_tokens: def harmonic_mean ( data ) : # For a justification for using harmonic mean for P/E ratios, see # http://fixthepitch.pellucid.com/comps-analysis-the-missing-harmony-of-summary-statistics/ # http://papers.ssrn.com/sol3/papers.cfm?abstract_id=2621087 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 )