<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Logarithmic Averaging / Geometric Mean in ArcGIS Spatial Analyst Questions</title>
    <link>https://community.esri.com/t5/arcgis-spatial-analyst-questions/logarithmic-averaging-geometric-mean/m-p/473948#M6792</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Koreen - did you figure out how to calculate the geometric mean with the raster calculator? Thanks!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 31 Oct 2014 18:16:10 GMT</pubDate>
    <dc:creator>MichaelAugust</dc:creator>
    <dc:date>2014-10-31T18:16:10Z</dc:date>
    <item>
      <title>Logarithmic Averaging / Geometric Mean</title>
      <link>https://community.esri.com/t5/arcgis-spatial-analyst-questions/logarithmic-averaging-geometric-mean/m-p/473946#M6790</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hello, I want to calculate the logarithmic average of the values of points as a raster.&amp;nbsp; &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Has anyone ever tried to do this?&amp;nbsp; &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;-k&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;FYI:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Geometric mean explained by wikipedia:&amp;nbsp; "The geometric mean, in mathematics, is a type of mean or average, which indicates the central tendency or typical value of a set of numbers. It is similar to the arithmetic mean, which is what most people think of with the word "average", except that the numbers are multiplied and then the nth root (where n is the count of numbers in the set) of the resulting product is taken."&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;A href="http://en.wikipedia.org/wiki/Geometric_mean"&gt;http://en.wikipedia.org/wiki/Geometric_mean&lt;/A&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 04 Oct 2010 17:33:54 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-spatial-analyst-questions/logarithmic-averaging-geometric-mean/m-p/473946#M6790</guid>
      <dc:creator>KoreenMillard</dc:creator>
      <dc:date>2010-10-04T17:33:54Z</dc:date>
    </item>
    <item>
      <title>Re: Logarithmic Averaging / Geometric Mean</title>
      <link>https://community.esri.com/t5/arcgis-spatial-analyst-questions/logarithmic-averaging-geometric-mean/m-p/473947#M6791</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Thanks very much!&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 08 Oct 2010 14:28:22 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-spatial-analyst-questions/logarithmic-averaging-geometric-mean/m-p/473947#M6791</guid>
      <dc:creator>KoreenMillard</dc:creator>
      <dc:date>2010-10-08T14:28:22Z</dc:date>
    </item>
    <item>
      <title>Re: Logarithmic Averaging / Geometric Mean</title>
      <link>https://community.esri.com/t5/arcgis-spatial-analyst-questions/logarithmic-averaging-geometric-mean/m-p/473948#M6792</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Koreen - did you figure out how to calculate the geometric mean with the raster calculator? Thanks!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 31 Oct 2014 18:16:10 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-spatial-analyst-questions/logarithmic-averaging-geometric-mean/m-p/473948#M6792</guid>
      <dc:creator>MichaelAugust</dc:creator>
      <dc:date>2014-10-31T18:16:10Z</dc:date>
    </item>
    <item>
      <title>Re: Logarithmic Averaging / Geometric Mean</title>
      <link>https://community.esri.com/t5/arcgis-spatial-analyst-questions/logarithmic-averaging-geometric-mean/m-p/473949#M6793</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;The way you'd do this using the 10x Raster Calculator tool would be:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE __default_attr="python" __jive_macro_name="code" class="jive_macro_code jive_text_macro _jivemacro_uid_14152586786632612" jivemacro_uid="_14152586786632612" modifiedtitle="true"&gt;
&lt;P&gt;("grid1" * "grid2" * "grid3" ) ** (1 / 3.)&lt;/P&gt;
&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Don't forget to include the "." after the number of rasters (3), as Python division is integer if both inputs are integer.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE __default_attr="python" __jive_macro_name="code" class="jive_macro_code jive_text_macro _jivemacro_uid_14152587896636516" jivemacro_uid="_14152587896636516"&gt;
&lt;P style="font-size: 11px; font-family: Menlo;"&gt;&amp;gt;&amp;gt;&amp;gt; 1 / 3&lt;/P&gt;
&lt;P style="font-size: 11px; font-family: Menlo;"&gt;0&lt;/P&gt;
&lt;P style="font-size: 11px; font-family: Menlo;"&gt;&amp;gt;&amp;gt;&amp;gt; 1 / 3.&lt;/P&gt;
&lt;P style="font-size: 11px; font-family: Menlo;"&gt;0.3333333333333333&lt;/P&gt;
&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 06 Nov 2014 07:26:49 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-spatial-analyst-questions/logarithmic-averaging-geometric-mean/m-p/473949#M6793</guid>
      <dc:creator>curtvprice</dc:creator>
      <dc:date>2014-11-06T07:26:49Z</dc:date>
    </item>
    <item>
      <title>Re: Logarithmic Averaging / Geometric Mean</title>
      <link>https://community.esri.com/t5/arcgis-spatial-analyst-questions/logarithmic-averaging-geometric-mean/m-p/473950#M6794</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Curtis - I meant calculate the geometric mean of all the individual cells contained in &lt;EM&gt;one&lt;/EM&gt; raster, like this:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;IMG alt="Geometric Mean" class="jive-image" height="42" src="http://www.freemathhelp.com/images/lessons/gmean1.gif" width="180" /&gt; &lt;/P&gt;&lt;P&gt;with each of those being an individual cell of my raster.&amp;nbsp; I think we realized that doing this to 1.2M cells in a raster simply implodes in Python, we couldn't get the script to do more than 50 or so values at one time.&amp;nbsp; Can someone out there with more programming experience explain why, or if there's a better way to do geometric mean in Python or ArcGIS?&lt;BR /&gt;thanks!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 06 Nov 2014 22:13:29 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-spatial-analyst-questions/logarithmic-averaging-geometric-mean/m-p/473950#M6794</guid>
      <dc:creator>MichaelAugust</dc:creator>
      <dc:date>2014-11-06T22:13:29Z</dc:date>
    </item>
    <item>
      <title>Re: Logarithmic Averaging / Geometric Mean</title>
      <link>https://community.esri.com/t5/arcgis-spatial-analyst-questions/logarithmic-averaging-geometric-mean/m-p/473951#M6795</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Not a spatial problem per-se, and the SciPy library does a pretty good job for problems like this. It'll be &lt;A href="http://blogs.esri.com/esri/esri-insider/2014/11/05/strengthening-the-link-between-gis-and-science"&gt;included in the 10.3 release&lt;/A&gt;, but can be downloaded and installed separately in 10.x. With that in place, convert your raster to a NumPy array, then use the statistics built in to SciPy to do the calculation:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE __default_attr="python" __jive_macro_name="code" class="jive_macro_code _jivemacro_uid_14153147149824558 jive_text_macro" jivemacro_uid="_14153147149824558" modifiedtitle="true"&gt;
&lt;P&gt;import scipy.stats&lt;/P&gt;
&lt;P&gt;rast_path = 'C:/my_input_raster.tif')&lt;/P&gt;
&lt;P&gt;raster_as_numpy_array&lt;CODE style="font-size: 11.1999998092651px;"&gt; &lt;SPAN class="o" style="font-size: 11.1999998092651px;"&gt;=&lt;/SPAN&gt; &lt;SPAN class="n" style="font-size: 11.1999998092651px;"&gt;arcpy&lt;/SPAN&gt;&lt;SPAN class="o" style="font-size: 11.1999998092651px;"&gt;.&lt;/SPAN&gt;&lt;SPAN class="n" style="font-size: 11.1999998092651px;"&gt;RasterToNumPyArray(rast_path&lt;/SPAN&gt;&lt;SPAN class="p" style="font-size: 11.1999998092651px;"&gt;)&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN class="p" style="font-size: 11.1999998092651px;"&gt;raster_geometric_mean = scipy.stats.stats.gmean(&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN class="p" style="font-size: 11.1999998092651px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; raster_as_numpy_array, axis=None)&lt;/SPAN&gt;&lt;/P&gt;



&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="p" style="font-size: 10pt;"&gt;Which for a raster of 10M values takes a few seconds for me to run.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="p" style="font-size: 10pt;"&gt;Hope that helps,&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;Shaun&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Edit: &lt;A href="https://community.esri.com/migrated-users/10169"&gt;Michael August&lt;/A&gt; I've updated my answer to include 'axis=None' which will compute the geometric mean for the whole matrix (instead of along one axis). With this change, it should work without any further steps.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 06 Nov 2014 22:59:39 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-spatial-analyst-questions/logarithmic-averaging-geometric-mean/m-p/473951#M6795</guid>
      <dc:creator>ShaunWalbridge</dc:creator>
      <dc:date>2014-11-06T22:59:39Z</dc:date>
    </item>
    <item>
      <title>Re: Logarithmic Averaging / Geometric Mean</title>
      <link>https://community.esri.com/t5/arcgis-spatial-analyst-questions/logarithmic-averaging-geometric-mean/m-p/473952#M6796</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;This is an alternate example of Curtis's example, not specifically what the OP wants. ...In the example below I created 3 numpy arrays representing your example, assuming everything under the root sign is a grid.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;

&amp;gt;&amp;gt;&amp;gt; import numpy as np


&amp;gt;&amp;gt;&amp;gt; base_form = np.arange(0,9,dtype='float64')


&amp;gt;&amp;gt;&amp;gt; base_form.reshape((3,3))


array([[ 0.,&amp;nbsp; 1.,&amp;nbsp; 2.],


&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; [ 3.,&amp;nbsp; 4.,&amp;nbsp; 5.],


&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; [ 6.,&amp;nbsp; 7.,&amp;nbsp; 8.]])


&amp;gt;&amp;gt;&amp;gt; a = ((np.ones_like(base_form))*2).reshape((3,3))


&amp;gt;&amp;gt;&amp;gt; b = ((np.ones_like(base_form))*4).reshape((3,3))


&amp;gt;&amp;gt;&amp;gt; c = ((np.ones_like(base_form))*8).reshape((3,3))


&amp;gt;&amp;gt;&amp;gt;


&amp;gt;&amp;gt;&amp;gt; d = a*b*c


&amp;gt;&amp;gt;&amp;gt; d


array([[ 64.,&amp;nbsp; 64.,&amp;nbsp; 64.],


&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; [ 64.,&amp;nbsp; 64.,&amp;nbsp; 64.],


&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; [ 64.,&amp;nbsp; 64.,&amp;nbsp; 64.]])


&amp;gt;&amp;gt;&amp;gt; root = ((np.ones_like(base_form))*(1.0/3.0)).reshape((3,3))


&amp;gt;&amp;gt;&amp;gt; root


array([[ 0.33333333,&amp;nbsp; 0.33333333,&amp;nbsp; 0.33333333],


&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; [ 0.33333333,&amp;nbsp; 0.33333333,&amp;nbsp; 0.33333333],


&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; [ 0.33333333,&amp;nbsp; 0.33333333,&amp;nbsp; 0.33333333]])


&amp;gt;&amp;gt;&amp;gt; gm = d**root


&amp;gt;&amp;gt;&amp;gt; gm


array([[ 4.,&amp;nbsp; 4.,&amp;nbsp; 4.],


&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; [ 4.,&amp;nbsp; 4.,&amp;nbsp; 4.],


&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; [ 4.,&amp;nbsp; 4.,&amp;nbsp; 4.]])


&amp;gt;&amp;gt;&amp;gt;




&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;it might be worth considering since you can use&lt;A href="http://resources.arcgis.com/en/help/main/10.2/index.html#/RasterToNumPyArray/03q300000029000000/" rel="nofollow noopener noreferrer" target="_blank"&gt; Raster to Numpy Array &lt;/A&gt;and the reverse to go between numpy and Arc&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Now on to the simpler question for the gm of a single raster.&amp;nbsp; You need the cumulative product of each cell, getting the last value in the row column which you do with a np.flatten function if it is a n*m array.&amp;nbsp; For a simple array. the syntax would be&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;

&amp;gt;&amp;gt;&amp;gt; # different example
&amp;gt;&amp;gt;&amp;gt; a = (np.arange(1,10)).reshape((3,3))
&amp;gt;&amp;gt;&amp;gt; a
array([[1, 2, 3],
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; [4, 5, 6],
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; [7, 8, 9]])
&amp;gt;&amp;gt;&amp;gt; cp = np.cumproduct(a)
&amp;gt;&amp;gt;&amp;gt; cp
array([&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 1,&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 2,&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 6,&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 24,&amp;nbsp;&amp;nbsp;&amp;nbsp; 120,&amp;nbsp;&amp;nbsp;&amp;nbsp; 720,&amp;nbsp;&amp;nbsp; 5040,&amp;nbsp; 40320,
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 362880])
&amp;gt;&amp;gt;&amp;gt; N = np.size(cp)
&amp;gt;&amp;gt;&amp;gt; N
9
&amp;gt;&amp;gt;&amp;gt; gm = (cp[-1])**(1.0/N)
&amp;gt;&amp;gt;&amp;gt; gm
4.1471662743969127
&amp;gt;&amp;gt;&amp;gt; 


&lt;/PRE&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;

Which is the same as excel...for your example,


on just those numbers....


&amp;gt;&amp;gt;&amp;gt; a = np.array([2.,4.,8.])


&amp;gt;&amp;gt;&amp;gt; cp = np.cumprod(a)


&amp;gt;&amp;gt;&amp;gt; cp


array([&amp;nbsp; 2.,&amp;nbsp;&amp;nbsp; 8.,&amp;nbsp; 64.])


&amp;gt;&amp;gt;&amp;gt; gm = cp[-1]**(1.0/np.size(cp))


&amp;gt;&amp;gt;&amp;gt; gm


3.9999999999999996


&amp;gt;&amp;gt;&amp;gt;

&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You can also use the alternate formulation to calculate the geometric mean for large numbers and/or arrays to prevent numeric over/under flows.&amp;nbsp; For example, a case of the 3x3 array as before and 1,000,000 int32 integers between 1 and 255&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;

&amp;gt;&amp;gt;&amp;gt; import numpy as np


&amp;gt;&amp;gt;&amp;gt; import random


&amp;gt;&amp;gt;&amp;gt; #************************ Simple example using log10&amp;nbsp; **************************


&amp;gt;&amp;gt;&amp;gt; a = (np.arange(1,10)).reshape((3,3))


&amp;gt;&amp;gt;&amp;gt; loga = np.log10(a)


&amp;gt;&amp;gt;&amp;gt; loga


array([[ 0.&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ,&amp;nbsp; 0.30103&amp;nbsp;&amp;nbsp; ,&amp;nbsp; 0.47712125],


&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; [ 0.60205999,&amp;nbsp; 0.69897&amp;nbsp;&amp;nbsp; ,&amp;nbsp; 0.77815125],


&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; [ 0.84509804,&amp;nbsp; 0.90308999,&amp;nbsp; 0.95424251]])


&amp;gt;&amp;gt;&amp;gt; cum_sum = np.cumsum(loga)


&amp;gt;&amp;gt;&amp;gt; N = np.size(a)


&amp;gt;&amp;gt;&amp;gt; N


9


&amp;gt;&amp;gt;&amp;gt; gm = 10.0**((cum_sum[-1])/N)


&amp;gt;&amp;gt;&amp;gt; gm


4.1471662743969135


&amp;gt;&amp;gt;&amp;gt; import numpy as np


&amp;gt;&amp;gt;&amp;gt; import random


&amp;gt;&amp;gt;&amp;gt; #***************************&amp;nbsp; large array * **************


&amp;gt;&amp;gt;&amp;gt; big = [ random.randint(1,255) for i in xrange(1000000)]


&amp;gt;&amp;gt;&amp;gt; a = np.array(big,dtype='int64')


&amp;gt;&amp;gt;&amp;gt; loga = np.log10(a)


&amp;gt;&amp;gt;&amp;gt; loga


array([ 2.32221929,&amp;nbsp; 1.95904139,&amp;nbsp; 2.38201704, ...,&amp;nbsp; 2.19865709,


&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 1.68124124,&amp;nbsp; 2.25285303])


&amp;gt;&amp;gt;&amp;gt; N = len(big)


&amp;gt;&amp;gt;&amp;gt; N


1000000


&amp;gt;&amp;gt;&amp;gt; cum_sum = np.cumsum(loga)


&amp;gt;&amp;gt;&amp;gt; cum_sum


array([&amp;nbsp; 2.32221929e+00,&amp;nbsp;&amp;nbsp; 4.28126069e+00,&amp;nbsp;&amp;nbsp; 6.66327773e+00, ...,


&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 1.97970102e+06,&amp;nbsp;&amp;nbsp; 1.97970270e+06,&amp;nbsp;&amp;nbsp; 1.97970495e+06])


&amp;gt;&amp;gt;&amp;gt; gm = 10.0**((cum_sum[-1])/N)


&amp;gt;&amp;gt;&amp;gt; gm


95.434401572885349


&amp;gt;&amp;gt;&amp;gt;

&lt;/PRE&gt;&lt;P&gt;An no other packages need to be installed&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 20:57:13 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-spatial-analyst-questions/logarithmic-averaging-geometric-mean/m-p/473952#M6796</guid>
      <dc:creator>DanPatterson_Retired</dc:creator>
      <dc:date>2021-12-11T20:57:13Z</dc:date>
    </item>
    <item>
      <title>Re: Logarithmic Averaging / Geometric Mean</title>
      <link>https://community.esri.com/t5/arcgis-spatial-analyst-questions/logarithmic-averaging-geometric-mean/m-p/473953#M6797</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Once upon a time there was a tool in ArcInfo Workstation GRID called DOCELL that would operate through all the cells of a raster. It was cool:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE __default_attr="plain" __jive_macro_name="code" class="jive_macro_code _jivemacro_uid_141533867653411 jive_text_macro" jivemacro_uid="_141533867653411"&gt;
&lt;P&gt;Grid: g = scalar(1)&lt;/P&gt;
&lt;P&gt;Grid: n = scalar(0)&lt;/P&gt;
&lt;P&gt;Grid: DOCELL&lt;/P&gt;
&lt;P&gt;:: g *= ingrid&lt;/P&gt;
&lt;P&gt;:: n += 1&lt;/P&gt;
&lt;P&gt;::&amp;nbsp; END&lt;/P&gt;
&lt;P&gt;Grid: g ^ (1 / float(n))&lt;/P&gt;




&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Talk about a blast from the past.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;A href="https://community.esri.com/migrated-users/31672"&gt;Shaun Walbridge&lt;/A&gt;‌ 's suggestion like a good way to do it nowadays. But if you can't get scipy installed (a bit of a lift actually) you could do something similar by converting the raster to a numpy array with RasterToNumpyArray() and doing the calculation there. That's what Dan did.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I just had a another thought - if the input is an integer grid with a VAT, something like this would work:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE __default_attr="python" __jive_macro_name="code" class="jive_macro_code _jivemacro_uid_14153390170665960 jive_text_macro" jivemacro_uid="_14153390170665960"&gt;
&lt;P&gt;sum = 0&lt;/P&gt;
&lt;P&gt;ncells = 0&lt;/P&gt;
&lt;P&gt;with arcpy.da.SearchCursor("ingrid", ["VALUE", "COUNT"]) as rows:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; for row in rows:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; for cc in range(row[1]): &lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; sum += sum * row[0] # running geometric sum of all cells in zone&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ncells += row[1]&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; # running cell count&lt;/P&gt;
&lt;P&gt;gmean = sum ** (1 / float(ncells))&lt;/P&gt;



&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;It's possible you may run into nasty numerical problems if the grid is very big as the sum gets huge, but this avoids converting the raster to numpy.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 07 Nov 2014 05:36:48 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-spatial-analyst-questions/logarithmic-averaging-geometric-mean/m-p/473953#M6797</guid>
      <dc:creator>curtvprice</dc:creator>
      <dc:date>2014-11-07T05:36:48Z</dc:date>
    </item>
    <item>
      <title>Re: Logarithmic Averaging / Geometric Mean</title>
      <link>https://community.esri.com/t5/arcgis-spatial-analyst-questions/logarithmic-averaging-geometric-mean/m-p/473954#M6798</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;PRE __default_attr="python" __jive_macro_name="code" class="jive_macro_code _jivemacro_uid_14153409163132351 jive_text_macro" jivemacro_uid="_14153409163132351" modifiedtitle="true"&gt;
&lt;P&gt;&amp;gt;&amp;gt;&amp;gt; raster_as_numpy_array = arcpy.RasterToNumPyArray('C:\Users\xxxxx\Downloads\q47121g52be.tif\q47121g52be.tif')&lt;/P&gt;
&lt;P&gt;&amp;gt;&amp;gt;&amp;gt; raster_geometric_mean = scipy.stats.mstats.gmean(raster_as_numpy_array)&lt;/P&gt;
&lt;P&gt;&amp;gt;&amp;gt;&amp;gt; raster_geometric_mean&lt;/P&gt;
&lt;P&gt;array([ 0.,&amp;nbsp; 0.,&amp;nbsp; 0., ...,&amp;nbsp; 0.,&amp;nbsp; 0.,&amp;nbsp; 0.], dtype=float16)&lt;/P&gt;
&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;So I tried the above on integer and float rasters and am not sure what I did wrong there...how do you get to the gm as a single reported value? If you can't tell I am fairly new at this point to Python -thanks you guys for all your help!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 07 Nov 2014 18:47:05 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-spatial-analyst-questions/logarithmic-averaging-geometric-mean/m-p/473954#M6798</guid>
      <dc:creator>MichaelAugust</dc:creator>
      <dc:date>2014-11-07T18:47:05Z</dc:date>
    </item>
    <item>
      <title>Re: Logarithmic Averaging / Geometric Mean</title>
      <link>https://community.esri.com/t5/arcgis-spatial-analyst-questions/logarithmic-averaging-geometric-mean/m-p/473955#M6799</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;once you have the array...check my examples in this thread&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 07 Nov 2014 18:55:26 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-spatial-analyst-questions/logarithmic-averaging-geometric-mean/m-p/473955#M6799</guid>
      <dc:creator>DanPatterson_Retired</dc:creator>
      <dc:date>2014-11-07T18:55:26Z</dc:date>
    </item>
    <item>
      <title>Re: Logarithmic Averaging / Geometric Mean</title>
      <link>https://community.esri.com/t5/arcgis-spatial-analyst-questions/logarithmic-averaging-geometric-mean/m-p/473956#M6800</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;PRE __default_attr="python" __jive_macro_name="code" class="jive_macro_code jive_text_macro _jivemacro_uid_14153868529456248" jivemacro_uid="_14153868529456248"&gt;
&lt;P&gt;&lt;/P&gt;
&lt;/PRE&gt;&lt;P&gt;So finish it with this part:&lt;/P&gt;&lt;PRE __default_attr="python" __jive_macro_name="code" class="jive_macro_code _jivemacro_uid_14153868620452950 jive_text_macro" jivemacro_uid="_14153868620452950"&gt;
&lt;P&gt;&amp;gt;&amp;gt;&amp;gt; cp = np.cumproduct(a) &lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;&amp;gt;&amp;gt;&amp;gt; cp &lt;/LI&gt;
&lt;LI&gt;array([&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN class="number"&gt;1,&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN class="number"&gt;2&lt;/SPAN&gt;,&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN class="number"&gt;6&lt;/SPAN&gt;,&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN class="number"&gt;24&lt;/SPAN&gt;,&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN class="number"&gt;120&lt;/SPAN&gt;,&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN class="number"&gt;720&lt;/SPAN&gt;,&amp;nbsp; &lt;SPAN class="number"&gt;5040&lt;/SPAN&gt;,&amp;nbsp; &lt;SPAN class="number"&gt;40320&lt;/SPAN&gt;,&amp;nbsp; &lt;/SPAN&gt;&lt;/LI&gt;
&lt;LI&gt;&lt;SPAN class="number"&gt;362880])&amp;nbsp; &lt;/SPAN&gt;&lt;/LI&gt;
&lt;LI&gt;&amp;gt;&amp;gt;&amp;gt; N = np.size(cp) &lt;/LI&gt;
&lt;LI&gt;&amp;gt;&amp;gt;&amp;gt; N &lt;/LI&gt;
&lt;LI&gt;&lt;SPAN class="number"&gt;9&amp;nbsp; &lt;/SPAN&gt;&lt;/LI&gt;
&lt;LI&gt;&amp;gt;&amp;gt;&amp;gt; gm = (cp[-&lt;SPAN class="number"&gt;1])**(&lt;SPAN class="number"&gt;1.0&lt;/SPAN&gt;/N)&amp;nbsp; &lt;/SPAN&gt;&lt;/LI&gt;
&lt;LI&gt;&amp;gt;&amp;gt;&amp;gt; gm &lt;/LI&gt;
&lt;LI&gt;&lt;SPAN class="number"&gt;4.1471662743969127 &lt;/SPAN&gt;&lt;/LI&gt;
&lt;/UL&gt;
&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 07 Nov 2014 19:01:17 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-spatial-analyst-questions/logarithmic-averaging-geometric-mean/m-p/473956#M6800</guid>
      <dc:creator>MichaelAugust</dc:creator>
      <dc:date>2014-11-07T19:01:17Z</dc:date>
    </item>
    <item>
      <title>Re: Logarithmic Averaging / Geometric Mean</title>
      <link>https://community.esri.com/t5/arcgis-spatial-analyst-questions/logarithmic-averaging-geometric-mean/m-p/473957#M6801</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;In my thread, I outlined two options...one using the cumulative product approach...and the other..the cumulative sum of the logs...&amp;nbsp; the cumulative product approach will fail if you have a large array and/or the numbers in the array contain large numbers due to numeric overflow.&amp;nbsp; The log approach suffers less from this.&amp;nbsp; The only difference is the way in which the final GM is determined.&amp;nbsp; I documented this for teaching purposes and to provide some context on GM use and the calculation pitfalls.&amp;nbsp; I am pretty sure that spreadsheet geometric mean functions don't use the cumulative product approach but rollout the log summation method behind the scenes..... So read my thread carefully...&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 07 Nov 2014 19:07:15 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-spatial-analyst-questions/logarithmic-averaging-geometric-mean/m-p/473957#M6801</guid>
      <dc:creator>DanPatterson_Retired</dc:creator>
      <dc:date>2014-11-07T19:07:15Z</dc:date>
    </item>
    <item>
      <title>Re: Logarithmic Averaging / Geometric Mean</title>
      <link>https://community.esri.com/t5/arcgis-spatial-analyst-questions/logarithmic-averaging-geometric-mean/m-p/473958#M6802</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Great - thanks Shaun!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 18 Nov 2014 20:36:34 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-spatial-analyst-questions/logarithmic-averaging-geometric-mean/m-p/473958#M6802</guid>
      <dc:creator>MichaelAugust</dc:creator>
      <dc:date>2014-11-18T20:36:34Z</dc:date>
    </item>
  </channel>
</rss>

