Calculate Geometric Mean in Python (Example Code)
In this tutorial you’ll learn how to compute the geometric mean in the Python programming language.
Creation of Example Data
x = [1, 4, 7, 3, 5, 7, 1, 2, 8, 4, 1, 7] # Constructing a list in Python print(x) # Displaying the example list # [1, 4, 7, 3, 5, 7, 1, 2, 8, 4, 1, 7] |
x = [1, 4, 7, 3, 5, 7, 1, 2, 8, 4, 1, 7] # Constructing a list in Python print(x) # Displaying the example list # [1, 4, 7, 3, 5, 7, 1, 2, 8, 4, 1, 7]
Example: Calculate Geometric Mean of List Using gmean() Function of SciPy Library
from scipy.stats import gmean |
from scipy.stats import gmean
print(gmean(x)) # Get geometric mean of list # 3.235703947155278 |
print(gmean(x)) # Get geometric mean of list # 3.235703947155278