0

i have large list of values:

[23.22, 50.44 .... 32.53]

after i should get next value:

reduce(operator.mul, [Decimal(i) for i in list])

print value - 4.248649022193430909459625077E+583 this value is too large but i have next action:

value**1/len(list)

I can not get the value if the list is very large - Is it possible to get the geometric mean in that case?

Lola
  • 2,591
  • 6
  • 24
  • 49

1 Answers1

6

Instead of multiplication of the items, sum their logarithms:

geometric_mean = (a1 * ... * an) ** (1/n) =
               = exp((log(a1) + .. + log(an)) / n) 
Dmitry Bychenko
  • 180,369
  • 20
  • 160
  • 215