# Is there a way to calculate the geometric mean of a raster in ArcGIS?

For the parameters whose values are log-normally distributed, we should calculate the geometric mean rather than arithmetic mean. In the Focal Statistics, there is option to calculate the arithmetic mean but I am interested to calculate the the geometric mean of my raster file. Is there any way to calculate the geometric mean of a raster in ArcGIS?

I want to calculate geometric mean of the surrounding neighborhood. The same way focal statistics calculate the arithmetic mean with defined map unit.

Based on this answer, just calculate the log, then the arithmetic mean, then the exponent. You can do this in the raster calculator with something like:

``````Exp(FocalStatistics(Ln(your_raster), your_neighbourhood, "MEAN"))
``````
• How do you define neighborhood? Jun 1 '20 at 5:29
• @FelixIP However you want. Circle, rectangle, annulus, kernel file, directional. It's all in the help for focal statistics. I saw no need to explain as the question wasn't about focal neighbourhoods. Jun 1 '20 at 5:47
• First step is correct. Next should be exponent of mean cell value from output raster .Single number, not a raster of unknown neighborhood. Jun 1 '20 at 6:53
• It is a single number. It's the mean value of the neighbourhood pixels. I take the question to be asking for a focal geometric mean, not a geometric mean of the entire raster, otherwise why would the question reference focal statistics? Jun 1 '20 at 8:09

You'll need to use script:

``````import numpy as np
iterable = arcpy.RasterToNumPyArray("DEM",nodata_to_value=np.NaN)
nan_array = np.isnan(iterable)
not_nan_array = ~ nan_array
a = iterable[not_nan_array]
A = np.log(a)
b = A.sum()/len(A)
print np.exp(b)
``````

credits to this post author.

• The OP has clarified the question and wants a geometric mean of a focal neighbourhood, not a geometric mean of the raster. Jun 2 '20 at 6:28
• @user2856 I see, you were right. What I still struggle to understand is log-normal distribution near cell. Hope asker knows what he really wants. Jun 2 '20 at 7:29