<?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: Find maximum value across a row in Geoprocessing Questions</title>
    <link>https://community.esri.com/t5/geoprocessing-questions/find-maximum-value-across-a-row/m-p/663341#M22101</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I played around with this a bit more given that you can't know the number of fields at runtime.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;What you can do is receive the arguments as a tuple.&amp;nbsp; So, in the code block, you do this:&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;def getMaxField(*args):&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;All the arguments are now available to you.&amp;nbsp; Assuming that you'll pass in the field values followed by the field names like this:&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;getMaxField(!FIELD_A_1!, !FIELD_A_2!, !FIELD_A_3!, "FIELD_A_1", "FIELD_A_2", "FIELD_A_3" )&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;You can receive the arguments and split them up into two arrays, one of values, one of names.&amp;nbsp; To get the total number of args, use the len() function.&amp;nbsp; Here is the code to create two arrays:&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&amp;nbsp; nfields = len(args)
&amp;nbsp; vals = args[0:nfields/2]
&amp;nbsp; fields = args[nfields/2:nfields]&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Next, we need to find the maximum value in the vals array.&amp;nbsp; Python has the max() function:&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;maxValue = max(vals)&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;But we don't want just the max value, we want the position in the array of the max value.&amp;nbsp; Python lists/tuples have the ().index method.&amp;nbsp; So, to find the index of the max value:&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&amp;nbsp; i = vals.index(max(vals))&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Now all that's left is to return the name of the field found at that index:&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&amp;nbsp; return fields&lt;I&gt;&lt;/I&gt;&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Here's the completed (verbose) code.&amp;nbsp; It worked for my simple test case.&amp;nbsp; It doesn't do anything about duplicate maximum values in the array.&amp;nbsp; &lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;def getMaxField(*args):
&amp;nbsp; nfields = len(args)
&amp;nbsp; vals = args[0:nfields/2]
&amp;nbsp; fields = args[nfields/2:nfields]
&amp;nbsp; i = vals.index(max(vals))
&amp;nbsp; return fields&lt;I&gt;&lt;/I&gt;&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sun, 12 Dec 2021 04:02:43 GMT</pubDate>
    <dc:creator>DaleHoneycutt</dc:creator>
    <dc:date>2021-12-12T04:02:43Z</dc:date>
    <item>
      <title>Find maximum value across a row</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/find-maximum-value-across-a-row/m-p/663336#M22096</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hi,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I am wondering if there is a tool that will look at a row, find the maximum value from column A, B, or C and then update column D with the name of the highest-ranked column. I could implement this as a cursor in Python but I would like to know if there is a set-based method that could be performed with ArcGIS Desktop (I have previously done this in SQL Server, but want to keep the requirements to a minimum).&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;At this stage the data is a polygon derived from an intersect, but it could also be modelled as a series of rasters.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Matt&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 30 Apr 2013 00:24:53 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/find-maximum-value-across-a-row/m-p/663336#M22096</guid>
      <dc:creator>MatthewBrown1</dc:creator>
      <dc:date>2013-04-30T00:24:53Z</dc:date>
    </item>
    <item>
      <title>Re: Find maximum value across a row</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/find-maximum-value-across-a-row/m-p/663337#M22097</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hi,&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;I think that it could be quite easy to implement it in Field Calculator, unless there are to many fields to check. Never heard about out-of-box solution. I would write python script as well.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Regards&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Arek&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 30 Apr 2013 13:40:08 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/find-maximum-value-across-a-row/m-p/663337#M22097</guid>
      <dc:creator>ArkadiuszMatoszka</dc:creator>
      <dc:date>2013-04-30T13:40:08Z</dc:date>
    </item>
    <item>
      <title>Re: Find maximum value across a row</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/find-maximum-value-across-a-row/m-p/663338#M22098</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;If you only need to do it the one time then simply use a combination of Select by Attributes and Field Caluclator on the table.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Select by attributes&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;columnA &amp;gt; columnB and ColumnA &amp;gt; columnC&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;This will give you all the columnA which are larger then both B and C&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Then from that selection query populate columnD with the Value of ColumnA&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Then do similar queries for ColumnB and ColumnC&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Do it three times and you are done.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt; You cold also create this as tool in model builder and save it as a button.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Out of the box.&amp;nbsp; But as I wrote if you only need to do it once or every few months it is just as well to do it with select by attributes and field calculator.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;Hi,&lt;BR /&gt;&lt;BR /&gt;I am wondering if there is a tool that will look at a row, find the maximum value from column A, B, or C and then update column D with the name of the highest-ranked column. I could implement this as a cursor in Python but I would like to know if there is a set-based method that could be performed with ArcGIS Desktop (I have previously done this in SQL Server, but want to keep the requirements to a minimum).&lt;BR /&gt;&lt;BR /&gt;At this stage the data is a polygon derived from an intersect, but it could also be modelled as a series of rasters.&lt;BR /&gt;&lt;BR /&gt;Thanks,&lt;BR /&gt;&lt;BR /&gt;Matt&lt;/BLOCKQUOTE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 30 Apr 2013 13:51:13 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/find-maximum-value-across-a-row/m-p/663338#M22098</guid>
      <dc:creator>RobertBorchert</dc:creator>
      <dc:date>2013-04-30T13:51:13Z</dc:date>
    </item>
    <item>
      <title>Re: Find maximum value across a row</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/find-maximum-value-across-a-row/m-p/663339#M22099</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;You can use Calculate Field.&amp;nbsp; The attached shows a graphic of a table named "A" with three numeric fields.&amp;nbsp; In the &lt;/SPAN&gt;&lt;STRONG&gt;Expression&lt;/STRONG&gt;&lt;SPAN&gt;, I call the getMaxField routine I wrote passing in the values of the three fields and the names of the three fields:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;getMaxField(!FIELD_A_1!, !FIELD_A_2!, !FIELD_A_3!, "FIELD_A_1", "FIELD_A_2", "FIELD_A_3" )&lt;/PRE&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The &lt;/SPAN&gt;&lt;STRONG&gt;Code Block&lt;/STRONG&gt;&lt;SPAN&gt;:&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;def getMaxField(v1, v2, v3, name1, name2, name3):
&amp;nbsp; maxval = max(v1,v2,v3)
&amp;nbsp; if maxval == v1:
&amp;nbsp;&amp;nbsp;&amp;nbsp; return name1
&amp;nbsp; if maxval == v2:
&amp;nbsp;&amp;nbsp; return name2
&amp;nbsp; return name3&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 04:02:41 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/find-maximum-value-across-a-row/m-p/663339#M22099</guid>
      <dc:creator>DaleHoneycutt</dc:creator>
      <dc:date>2021-12-12T04:02:41Z</dc:date>
    </item>
    <item>
      <title>Re: Find maximum value across a row</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/find-maximum-value-across-a-row/m-p/663340#M22100</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Thanks for your answers.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Dale's code block is similar to the SQL I have used for this problem. I must remember that the code block can be quite powerful!&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;One thing I didn't realise is that the number of columns will vary with each dataset this is run on - there could be up to six colums or only one. So defining the function to accommodate this could be tricky. I guess I could just define all six and add any missing columns so the expression doen't return an error.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I will try to implement this later and post back.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Matt&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 30 Apr 2013 23:17:43 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/find-maximum-value-across-a-row/m-p/663340#M22100</guid>
      <dc:creator>MatthewBrown1</dc:creator>
      <dc:date>2013-04-30T23:17:43Z</dc:date>
    </item>
    <item>
      <title>Re: Find maximum value across a row</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/find-maximum-value-across-a-row/m-p/663341#M22101</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I played around with this a bit more given that you can't know the number of fields at runtime.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;What you can do is receive the arguments as a tuple.&amp;nbsp; So, in the code block, you do this:&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;def getMaxField(*args):&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;All the arguments are now available to you.&amp;nbsp; Assuming that you'll pass in the field values followed by the field names like this:&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;getMaxField(!FIELD_A_1!, !FIELD_A_2!, !FIELD_A_3!, "FIELD_A_1", "FIELD_A_2", "FIELD_A_3" )&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;You can receive the arguments and split them up into two arrays, one of values, one of names.&amp;nbsp; To get the total number of args, use the len() function.&amp;nbsp; Here is the code to create two arrays:&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&amp;nbsp; nfields = len(args)
&amp;nbsp; vals = args[0:nfields/2]
&amp;nbsp; fields = args[nfields/2:nfields]&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Next, we need to find the maximum value in the vals array.&amp;nbsp; Python has the max() function:&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;maxValue = max(vals)&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;But we don't want just the max value, we want the position in the array of the max value.&amp;nbsp; Python lists/tuples have the ().index method.&amp;nbsp; So, to find the index of the max value:&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&amp;nbsp; i = vals.index(max(vals))&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Now all that's left is to return the name of the field found at that index:&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&amp;nbsp; return fields&lt;I&gt;&lt;/I&gt;&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Here's the completed (verbose) code.&amp;nbsp; It worked for my simple test case.&amp;nbsp; It doesn't do anything about duplicate maximum values in the array.&amp;nbsp; &lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;def getMaxField(*args):
&amp;nbsp; nfields = len(args)
&amp;nbsp; vals = args[0:nfields/2]
&amp;nbsp; fields = args[nfields/2:nfields]
&amp;nbsp; i = vals.index(max(vals))
&amp;nbsp; return fields&lt;I&gt;&lt;/I&gt;&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 04:02:43 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/find-maximum-value-across-a-row/m-p/663341#M22101</guid>
      <dc:creator>DaleHoneycutt</dc:creator>
      <dc:date>2021-12-12T04:02:43Z</dc:date>
    </item>
  </channel>
</rss>

