<?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: arcpy calculatefield expression codeblock exponential in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/arcpy-calculatefield-expression-codeblock/m-p/1037479#M60433</link>
    <description>&lt;P&gt;You didn't import the spatial analyst&lt;/P&gt;&lt;P&gt;&lt;A href="https://pro.arcgis.com/en/pro-app/latest/tool-reference/spatial-analyst/exp.htm" target="_blank"&gt;Exp (Spatial Analyst)—ArcGIS Pro | Documentation&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="hljs-keyword"&gt;from&lt;/SPAN&gt;&lt;SPAN&gt; arcpy.sa &lt;/SPAN&gt;&lt;SPAN class="hljs-keyword"&gt;import Exp&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="hljs-keyword"&gt;And I hope your code block is formatted properly because you copy paste won't work&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="hljs-keyword"&gt;&lt;A href="https://community.esri.com/t5/python-blog/code-formatting-the-community-version/ba-p/1007633" target="_blank"&gt;Code formatting ... the Community Version - Esri Community&lt;/A&gt;&lt;/SPAN&gt;&lt;/P&gt;</description>
    <pubDate>Wed, 17 Mar 2021 04:07:09 GMT</pubDate>
    <dc:creator>DanPatterson</dc:creator>
    <dc:date>2021-03-17T04:07:09Z</dc:date>
    <item>
      <title>arcpy calculatefield expression codeblock exponential</title>
      <link>https://community.esri.com/t5/python-questions/arcpy-calculatefield-expression-codeblock/m-p/1037458#M60429</link>
      <description>&lt;P&gt;Hello colleagues&lt;/P&gt;&lt;P&gt;I am trying to use a formula in python. It is a raster dataset and I am trying to calculate a field based on an equation.&lt;/P&gt;&lt;P&gt;Here is the code&lt;/P&gt;&lt;P&gt;====================&lt;/P&gt;&lt;P&gt;&lt;FONT color="#008000"&gt;inTable = "C:/Data/A3_Large_projects/Fuelloadmodels/Data/GDB/Yr2021.gdb/combo"&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#008000"&gt;fieldName = "Bark_load"&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#008000"&gt;expression = "t_RF(!Bark_r!, !Bark_k!, !Bark_c!, !since_fire!)"&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#008000"&gt;codeblock = """&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#008000"&gt;def t_RF(Bark_r, Bark_k, Bark_c, since_fire):&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#008000"&gt;&amp;nbsp; if since_fire &amp;gt;= 0:&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#008000"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return 7.437 /(1+937.8 * Exp ( -1.905 *( Bark_r *(1 - Exp ( - Bark_k * since_fire ) )+ Bark_c )))&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#008000"&gt;&amp;nbsp; else:&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#008000"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return 999 """&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#008000"&gt;arcpy.CalculateField_management(inTable, fieldName, expression, "PYTHON_9.3", codeblock)&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;====================&lt;/P&gt;&lt;P&gt;End code&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Error message starts&lt;/P&gt;&lt;P&gt;====================&lt;/P&gt;&lt;P&gt;&lt;FONT color="#FF0000"&gt;Traceback (most recent call last):&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#FF0000"&gt;&amp;nbsp; File "C:\Data\A3_Large_projects\Fuelloadmodels\Python_script\Fuelhazard.py", line 126, in &amp;lt;module&amp;gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#FF0000"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.CalculateField_management(inTable, fieldName, expression, "PYTHON_9.3", codeblock)&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#FF0000"&gt;&amp;nbsp; File "C:\Program Files (x86)\ArcGIS\Desktop10.5\ArcPy\arcpy\management.py", line 3661, in CalculateField&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#FF0000"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; raise e&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#FF0000"&gt;ExecuteError: ERROR 000539: Error running expression: t_RF(2.5, 0.2, 0.7, 1)&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#FF0000"&gt;Traceback (most recent call last):&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#FF0000"&gt;&amp;nbsp; File "&amp;lt;expression&amp;gt;", line 1, in &amp;lt;module&amp;gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#FF0000"&gt;&amp;nbsp; File "&amp;lt;string&amp;gt;", line 4, in t_RF&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#FF0000"&gt;NameError: global name 'Exp' is not defined&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#FF0000"&gt;Failed to execute (CalculateField).&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;====================&lt;/P&gt;&lt;P&gt;End error message&lt;/P&gt;&lt;P&gt;I am relatively new in python. Trying to understand the error message. Will appreciate any help.&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Wed, 17 Mar 2021 02:28:40 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/arcpy-calculatefield-expression-codeblock/m-p/1037458#M60429</guid>
      <dc:creator>SalahuddinAhmad</dc:creator>
      <dc:date>2021-03-17T02:28:40Z</dc:date>
    </item>
    <item>
      <title>Re: arcpy calculatefield expression codeblock exponential</title>
      <link>https://community.esri.com/t5/python-questions/arcpy-calculatefield-expression-codeblock/m-p/1037479#M60433</link>
      <description>&lt;P&gt;You didn't import the spatial analyst&lt;/P&gt;&lt;P&gt;&lt;A href="https://pro.arcgis.com/en/pro-app/latest/tool-reference/spatial-analyst/exp.htm" target="_blank"&gt;Exp (Spatial Analyst)—ArcGIS Pro | Documentation&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="hljs-keyword"&gt;from&lt;/SPAN&gt;&lt;SPAN&gt; arcpy.sa &lt;/SPAN&gt;&lt;SPAN class="hljs-keyword"&gt;import Exp&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="hljs-keyword"&gt;And I hope your code block is formatted properly because you copy paste won't work&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="hljs-keyword"&gt;&lt;A href="https://community.esri.com/t5/python-blog/code-formatting-the-community-version/ba-p/1007633" target="_blank"&gt;Code formatting ... the Community Version - Esri Community&lt;/A&gt;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 17 Mar 2021 04:07:09 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/arcpy-calculatefield-expression-codeblock/m-p/1037479#M60433</guid>
      <dc:creator>DanPatterson</dc:creator>
      <dc:date>2021-03-17T04:07:09Z</dc:date>
    </item>
    <item>
      <title>Re: arcpy calculatefield expression codeblock exponential</title>
      <link>https://community.esri.com/t5/python-questions/arcpy-calculatefield-expression-codeblock/m-p/1037486#M60435</link>
      <description>&lt;P&gt;This is a raster dataset? You are using Calculate Field, it so sounds like&amp;nbsp;&lt;SPAN&gt;!Bark_r!, !Bark_k!, !Bark_c!, !since_fire!) are all fields in a raster table. (Combine output?)&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;If that's the case, math.exp should be used not Exp here.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;&amp;gt;&amp;gt;&amp;gt; import math
&amp;gt;&amp;gt;&amp;gt; math.exp(1)
2.718281828459045&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;However, if I am wrong and these are rasters, not fields in a table,&amp;nbsp;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/215600"&gt;@DanPatterson&lt;/a&gt;&amp;nbsp;is correct and you should be doing something like&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;from arcpy.sa import *
outraster = 7.437 /(1+937.8 * Exp ( -1.905 * Bark_k ...&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 17 Mar 2021 04:42:59 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/arcpy-calculatefield-expression-codeblock/m-p/1037486#M60435</guid>
      <dc:creator>curtvprice</dc:creator>
      <dc:date>2021-03-17T04:42:59Z</dc:date>
    </item>
    <item>
      <title>Re: arcpy calculatefield expression codeblock exponential</title>
      <link>https://community.esri.com/t5/python-questions/arcpy-calculatefield-expression-codeblock/m-p/1037844#M60451</link>
      <description>&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="exp.JPG" style="width: 999px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/8738iA0E4E84FE38668B2/image-size/large?v=v2&amp;amp;px=999" role="button" title="exp.JPG" alt="exp.JPG" /&gt;&lt;/span&gt;Thanks,&amp;nbsp;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/1325"&gt;@curtvprice&lt;/a&gt;&amp;nbsp;for your help.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Yes, it is a raster dataset name "combo" and those are the field names from the raster table. I trying to calculate a field called "Bark_load" based on the following equation.&amp;nbsp;&lt;/P&gt;&lt;P&gt;VB&lt;/P&gt;&lt;P&gt;7.437 /(1+937.8 * Exp ( -1.905 *( Bark_r *(1 - Exp ( - Bark_k * since_fire ) )+ Bark_c )))&lt;/P&gt;&lt;P&gt;Python&lt;/P&gt;&lt;P&gt;7.437 /(1+937.8 * math.exp(-1.905 *( !Bark_r! *(1 - math.exp(- !Bark_k! * !Since_Fire! )) + !Bark_c! )))&lt;/P&gt;&lt;P&gt;please note:&amp;nbsp;exp is exponential function not Exp (Spatial Analyst)&lt;/P&gt;&lt;P&gt;I have a modelbuilder and this equation works there as VB and Python.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks for any further help.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 17 Mar 2021 22:50:38 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/arcpy-calculatefield-expression-codeblock/m-p/1037844#M60451</guid>
      <dc:creator>SalahuddinAhmad</dc:creator>
      <dc:date>2021-03-17T22:50:38Z</dc:date>
    </item>
    <item>
      <title>Re: arcpy calculatefield expression codeblock exponential</title>
      <link>https://community.esri.com/t5/python-questions/arcpy-calculatefield-expression-codeblock/m-p/1037875#M60452</link>
      <description>&lt;P&gt;exponent&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;7.437 /(1+937.8**(-1.905 * Bark_k ...&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp; exponents in python are **&lt;/P&gt;&lt;P&gt;2**4&lt;BR /&gt;16&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 17 Mar 2021 23:31:40 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/arcpy-calculatefield-expression-codeblock/m-p/1037875#M60452</guid>
      <dc:creator>DanPatterson</dc:creator>
      <dc:date>2021-03-17T23:31:40Z</dc:date>
    </item>
    <item>
      <title>Re: arcpy calculatefield expression codeblock exponential</title>
      <link>https://community.esri.com/t5/python-questions/arcpy-calculatefield-expression-codeblock/m-p/1037881#M60453</link>
      <description>&lt;P&gt;Dan: the VB function and Raster tool Exp is "e to the value" not&amp;nbsp; ^ (VB) or ** (Python)&lt;/P&gt;</description>
      <pubDate>Wed, 17 Mar 2021 23:48:21 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/arcpy-calculatefield-expression-codeblock/m-p/1037881#M60453</guid>
      <dc:creator>curtvprice</dc:creator>
      <dc:date>2021-03-17T23:48:21Z</dc:date>
    </item>
    <item>
      <title>Re: arcpy calculatefield expression codeblock exponential</title>
      <link>https://community.esri.com/t5/python-questions/arcpy-calculatefield-expression-codeblock/m-p/1037888#M60454</link>
      <description>&lt;P&gt;Here is how that works with the tool:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;inTable = "C:/Data/A3_Large_projects/Fuelloadmodels/Data/GDB/Yr2021.gdb/combo"
fieldName = "Bark_load"
expr = "t_RF(!Bark_r!, !Bark_k, !Bark_c!, !since_fire!)"
cblock = """
def t_RF(rr, kk, cc, sfire):
    import math
    if sfire &amp;gt;= 0:
        return (
            7.437 /
                ( 1 + 937.8 * math.exp(-1.905 * 
                    (rr * (1 - math.exp(-kk * sfire)) + cc )))
                )
    else:
        return 999 """
arcpy.CalculateField_management(inTable, fieldName, expr, "PYTHON_9.3", cblock)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I should mention that arcpy.da.UpdateCursor is a more common way to do this with complex field calculations in Python (less overhead):&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;inTable = "C:/Data/A3_Large_projects/Fuelloadmodels/Data/GDB/Yr2021.gdb/combo"
fieldName = "Bark_load"
def t_RF(rr, kk, cc, sfire):
    import math
    if sfire &amp;gt;= 0:
        return (
            7.437 /
                ( 1 + 937.8 * math.exp(-1.905 * 
                    (rr * (1 - math.exp(-kk * sfire)) + cc )))
                )
    else:
        return 999
with arcpy.da.UpdateCursor(inTable, 
    ["Bark_load", "Bark_r", "Bark_k", "Bark_c","since_fire"]) as rows:
    for row in rows:
        bark_load, rr, kk, cc, sfire = row
        row[0] = t_RF(rr, kk, cc, sfire)
        rows.updateRow(row)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 18 Mar 2021 00:24:33 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/arcpy-calculatefield-expression-codeblock/m-p/1037888#M60454</guid>
      <dc:creator>curtvprice</dc:creator>
      <dc:date>2021-03-18T00:24:33Z</dc:date>
    </item>
    <item>
      <title>Re: arcpy calculatefield expression codeblock exponential</title>
      <link>https://community.esri.com/t5/python-questions/arcpy-calculatefield-expression-codeblock/m-p/1037899#M60455</link>
      <description>&lt;P&gt;grief... too many e E eE Exp EXP 's &lt;span class="lia-unicode-emoji" title=":winking_face:"&gt;😉&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 18 Mar 2021 01:31:43 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/arcpy-calculatefield-expression-codeblock/m-p/1037899#M60455</guid>
      <dc:creator>DanPatterson</dc:creator>
      <dc:date>2021-03-18T01:31:43Z</dc:date>
    </item>
  </channel>
</rss>

