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]

Example: Calculate Geometric Mean of List Using gmean() Function of SciPy Library

from scipy.stats import gmean
print(gmean(x))                             # Get geometric mean of list
# 3.235703947155278

Leave a Reply

Your email address will not be published. Required fields are marked *

Fill out this field
Fill out this field
Please enter a valid email address.
You need to agree with the terms to proceed

Menu
Top