Date Tags python

Need to calculate a geometric mean in Python? You could use Numpy or this one-liner:

# NOTE: This import is only needed for Python3.
from functools import reduce

# Geometric mean of list `n`:
geomean = lambda n: reduce(lambda x,y: x*y, n) ** (1.0 / len(n))

print(geomean([1,2,3,4]))
# Result: 2.2133638394

Hi, I am Jeff Rimko!
A computer engineer and software developer in the greater Pittsburgh, Pennsylvania area.