scipy.stats.gmean(array, axis=0, dtype=None) calculates the geometric mean of the array elements along the specified axis of the array (list in python).
It’s formula –

Parameters :
array: Input array or obejct having the elements to calculate the geometric mean.
axis: Axis along which the mean is to be computed. By default axis = 0
dtype: It sets the type of returned element.Returns : Geometric mean of the array elements based on the set parameters.
Code #1:
# Geometric Mean from scipy.stats.mstats import gmean arr1 = gmean([1, 3, 27]) print("Geometric Mean is :", arr1) |
Geometric Mean is : 4.32674871092
Code #2: With multi-dimensional data
# Geometric Mean from scipy.stats.mstats import gmean arr1 = [[1, 3, 27], [3, 4, 6], [7, 6, 3], [3, 6, 8]] print("Geometric Mean is :", gmean(arr1)) # using axis = 0 print("\nGeometric Mean is with default axis = 0 : \n", gmean(arr1, axis = 0)) # using axis = 1 print("\nGeometric Mean is with default axis = 1 : \n", gmean(arr1, axis = 1)) |
Geometric Mean is : [ 2.81731325 4.55901411 7.89644408] Geometric Mean is with default axis = 0 : [ 2.81731325 4.55901411 7.89644408] Geometric Mean is with default axis = 1 : [ 4.32674871 4.16016765 5.01329793 5.24148279]
Recommended Posts:
- sciPy stats.tsem() function | Python
- sciPy stats.tvar() function | Python
- scipy stats.tmin() function | Python
- sciPy stats.tstd() function | Python
- sciPy stats.tmax() function | Python
- sciPy stats.describe() function | Python
- sciPy stats.mean() function | Python
- sciPy stats.nanmedian() function | Python
- sciPy stats.nanstd() function | Python
- sciPy stats.nanmean() function | Python
- scipy stats.moment() function | Python
- scipy stats.mode() function | Python
- scipy stats.normaltest() function | Python
- scipy stats.skewtest() function | Python
- scipy stats.kurtosis() function | Python
- scipy stats.kurtosistest() function | Python
- sciPy stats.relfreq() function | Python
- sciPy stats.scoreatpercentile() function | Python
- sciPy stats.itemfreq() function | Python
- sciPy stats.histogram() function | Python
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.

