<?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: Can I use a Numpy Expression in the Field calculator inside PRO? in ArcGIS Pro Questions</title>
    <link>https://community.esri.com/t5/arcgis-pro-questions/can-i-use-a-numpy-expression-in-the-field/m-p/1053039#M40423</link>
    <description>&lt;P&gt;Do the work outside and bring it back in.&lt;/P&gt;&lt;P&gt;Close Pro to make sure any file locks are gone.&lt;/P&gt;&lt;P&gt;Verbose example&lt;/P&gt;&lt;LI-CODE lang="python"&gt;from arcpy.da import TableToNumPyArray, ExtendTable
tbl = r"C:\arcpro_npg\npg\Project_npg\npgeom.gdb\sample_10k"  # my table
arr = TableToNumPyArray(tbl, ["OID@", "Age"])  # the objectid field and another
arr1 = arr["OID@"]  # make oid values
arr2 = arr["Age"]   # Get the values you are interested
count = arr2.shape[0]  # get the length of the array
mx = np.nanmax(arr2)  # ---- now get the max... nanmax accounts for nulls
vals = np.repeat(mx, count) # ---- repeat the maximum "count" times
# create output  ---- excitement builds
z = np.empty_like(arr)  # build the output array
z.dtype.names = ("OID@", 'Max_Vals')  # make your output names
z["OID@"] = arr1    # put the id values in
z['Max_Vals'] = vals  # put the max in
ExtendTable(tbl, "OID@", z, "OID@")  # magic-orama ... like a join&lt;/LI-CODE&gt;&lt;P&gt;Now open Pro and open the table to see the results.&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="max's.png" style="width: 99px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/12232i0174CD1880CE440F/image-size/medium?v=v2&amp;amp;px=400" role="button" title="max's.png" alt="max's.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;I have helper functions that expedite this, but you need to understand the procedure first.&lt;/P&gt;&lt;P&gt;numpy is extremely powerful and I have numerous blogs on its use with arcpy in the Python Blogs... look for me and me before retirement.&lt;/P&gt;</description>
    <pubDate>Fri, 30 Apr 2021 01:34:57 GMT</pubDate>
    <dc:creator>DanPatterson</dc:creator>
    <dc:date>2021-04-30T01:34:57Z</dc:date>
    <item>
      <title>Can I use a Numpy Expression in the Field calculator inside PRO?</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/can-i-use-a-numpy-expression-in-the-field/m-p/1052991#M40420</link>
      <description>&lt;P&gt;&lt;FONT face="lucida sans unicode,lucida sans"&gt;Hello,&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="lucida sans unicode,lucida sans"&gt;I am trying to calculate a field in ArcGIS PRO. The field should contain a constant in every row. This constant will be equal to the maximum of another column in the table.dbf&amp;nbsp; WFr_100.&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="lucida sans unicode,lucida sans"&gt;I can get to the number with this code, but I would like to do it through the field calculator inside Arcgis PRO.&amp;nbsp; Is there a way to do that?&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="book antiqua,palatino"&gt;# Import system modules &lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="book antiqua,palatino"&gt;import arcpy&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="book antiqua,palatino"&gt;import numpy &lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="book antiqua,palatino"&gt;# Set environment settings &lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="book antiqua,palatino"&gt;arcpy.env.workspace = r"C:\Users\MD \Documents\ArcGIS\Projects\IP\Default.gdb" &lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="book antiqua,palatino"&gt;input = "WFr_100" arr = arcpy.da.TableToNumPyArray(input, ('CMass')) &lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="book antiqua,palatino"&gt;x=(arr["CMass"].max()) &lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="book antiqua,palatino"&gt;print(x)&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 29 Apr 2021 23:00:17 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/can-i-use-a-numpy-expression-in-the-field/m-p/1052991#M40420</guid>
      <dc:creator>mlopezr95984</dc:creator>
      <dc:date>2021-04-29T23:00:17Z</dc:date>
    </item>
    <item>
      <title>Re: Can I use a Numpy Expression in the Field calculator inside PRO?</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/can-i-use-a-numpy-expression-in-the-field/m-p/1053039#M40423</link>
      <description>&lt;P&gt;Do the work outside and bring it back in.&lt;/P&gt;&lt;P&gt;Close Pro to make sure any file locks are gone.&lt;/P&gt;&lt;P&gt;Verbose example&lt;/P&gt;&lt;LI-CODE lang="python"&gt;from arcpy.da import TableToNumPyArray, ExtendTable
tbl = r"C:\arcpro_npg\npg\Project_npg\npgeom.gdb\sample_10k"  # my table
arr = TableToNumPyArray(tbl, ["OID@", "Age"])  # the objectid field and another
arr1 = arr["OID@"]  # make oid values
arr2 = arr["Age"]   # Get the values you are interested
count = arr2.shape[0]  # get the length of the array
mx = np.nanmax(arr2)  # ---- now get the max... nanmax accounts for nulls
vals = np.repeat(mx, count) # ---- repeat the maximum "count" times
# create output  ---- excitement builds
z = np.empty_like(arr)  # build the output array
z.dtype.names = ("OID@", 'Max_Vals')  # make your output names
z["OID@"] = arr1    # put the id values in
z['Max_Vals'] = vals  # put the max in
ExtendTable(tbl, "OID@", z, "OID@")  # magic-orama ... like a join&lt;/LI-CODE&gt;&lt;P&gt;Now open Pro and open the table to see the results.&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="max's.png" style="width: 99px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/12232i0174CD1880CE440F/image-size/medium?v=v2&amp;amp;px=400" role="button" title="max's.png" alt="max's.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;I have helper functions that expedite this, but you need to understand the procedure first.&lt;/P&gt;&lt;P&gt;numpy is extremely powerful and I have numerous blogs on its use with arcpy in the Python Blogs... look for me and me before retirement.&lt;/P&gt;</description>
      <pubDate>Fri, 30 Apr 2021 01:34:57 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/can-i-use-a-numpy-expression-in-the-field/m-p/1053039#M40423</guid>
      <dc:creator>DanPatterson</dc:creator>
      <dc:date>2021-04-30T01:34:57Z</dc:date>
    </item>
    <item>
      <title>Re: Can I use a Numpy Expression in the Field calculator inside PRO?</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/can-i-use-a-numpy-expression-in-the-field/m-p/1053413#M40460</link>
      <description>&lt;P&gt;Spot on, Dan! Thank you.&lt;/P&gt;</description>
      <pubDate>Fri, 30 Apr 2021 20:07:10 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/can-i-use-a-numpy-expression-in-the-field/m-p/1053413#M40460</guid>
      <dc:creator>mlopezr95984</dc:creator>
      <dc:date>2021-04-30T20:07:10Z</dc:date>
    </item>
  </channel>
</rss>

