How to calculate the geometric mean

The geometric mean is another type of average which shows the central tendency of a set of data. To calculate the geometric mean of a set of N data values we need to extract the Nth root of their product.

In mathematics there is no particular notation for the geometric mean. For our example we are going to use:

\[x_{GM} = \sqrt[N]{x_1 \cdot x_2 \cdot x_3 \cdot … x_N}\]

The general mathematical expression for the geometric mean is:

\[x_{GM} = \sqrt[N]{\prod _{i=1}^{N}x_{i}}\]

We can also write the mathematical expression of the geometric mean using rational exponents instead of radical:

\[x_{GM} = \left(\prod _{i=1}^{N}x_{i}\right)^{\frac {1}{N}}\]

Example: Calculate the geometric mean (average) of the monthly minimum temperature for the given set of data.

MonthMinimum temperature [°C]

We are given 12 measurements of the temperatures, the minimum value for each month. The minimum average temperature for the whole year is the geometric mean of the data set:

\[x_{GM} = \sqrt[12]{2 \cdot 4 \cdot 8 \cdot 13 \cdot 16 \cdot 21 \cdot 23 \cdot 22 \cdot 20 \cdot 17 \cdot 13 \cdot 6}=\sqrt[12]{3751000000000}=11.164662\]

For a better understanding of the result we are going to plot:

  • each monthly minimum temperature as a bar plot
  • the geometric mean (yearly minimum average temperature) as a line
Monthly minimum temperature and yearly average (geometric mean)

Image: Monthly minimum temperature and yearly average (geometric mean)

As a programming exercise, we’ll write a Scilab script which calculates the geometric mean for the same set of data:

data_N = [2 4 8 13 16 21 23 22 20 17 13 6];
length_N = length(data_N);
prod_N = 1;

for i=1:length_N
 prod_N = prod_N * data_N(i); 

x_GM = prod_N^(1/length_N);
mprintf("The geometric mean is: %f", x_GM);

For further practicing we are going to write down a C script which calculates the geometric mean for the same set of data (temperatures):


int main(void)
 double data_N[12] = {2,4,8,13,16,21,23,22,20,17,13,6};
 int i;
 double product_N = 1;
 double x_GM = 0;
 double exponent;
 double length_N = 12;

for (i=0;i<length_N;i++){
 product_N = product_N * data_N[i];

exponent = 1/length_N;
 x_GM = pow(product_N,exponent);
 printf("The geometric mean is %f: \n",x_GM);

return 0;


For any questions or observations regarding this tutorial please use the comment form below.

Don’t forget to Like, Share and Subscribe!

Leave a Reply

Ad Blocker Detected

Dear user, Our website provides free and high quality content by displaying ads to our visitors. Please support us by disabling your Ad blocker for our site. Thank you!