<?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: How to improve the python efficiency? in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/how-to-improve-the-python-efficiency/m-p/493470#M38712</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;

# set the workspace
arcpy.env.workspace = r"C:\pathtomyworkspace"

#set a different workspace
arcpy.env.workspace = r"C:\pathtomydifferentworkspace"

#clean up all items in the workspace
fcs = arcpy.ListFeatureClasses()
tabs = arcpy.ListTables()
rasters = arcpy.ListRasters()
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 
### for each FeatClass in the list of fcs's, delete it.
for f in fcs:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.Delete_management(f)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.AddMessage("deleted: " + f)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 
### for each TableClass in the list of tab's, delete it.
for t in tabs:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.Delete_management(t)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.AddMessage("deleted: " + t)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 
### for each Raster in the workspace, delete it
for r in rasters:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.Delete_management(r)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.AddMessage("deleted " + str(r))

&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Post the code you percieve to be too slow for opinions or suggestions on how to improve it.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sat, 11 Dec 2021 21:42:58 GMT</pubDate>
    <dc:creator>JamesCrandall</dc:creator>
    <dc:date>2021-12-11T21:42:58Z</dc:date>
    <item>
      <title>How to improve the python efficiency?</title>
      <link>https://community.esri.com/t5/python-questions/how-to-improve-the-python-efficiency/m-p/493469#M38711</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;i am using arcpy to process some raster data and output a raster.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;but now, i meet some problems.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;1. how to flush the memory of temporary data.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;2. how can i set a temp path for the temporary data.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;3. finanlly and biggest problem is when i output a raster, it taked a long time (e.g. output a 18MB data need more than 10 min)?&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 26 Aug 2013 14:03:20 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-improve-the-python-efficiency/m-p/493469#M38711</guid>
      <dc:creator>ZuoqiChen</dc:creator>
      <dc:date>2013-08-26T14:03:20Z</dc:date>
    </item>
    <item>
      <title>Re: How to improve the python efficiency?</title>
      <link>https://community.esri.com/t5/python-questions/how-to-improve-the-python-efficiency/m-p/493470#M38712</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;

# set the workspace
arcpy.env.workspace = r"C:\pathtomyworkspace"

#set a different workspace
arcpy.env.workspace = r"C:\pathtomydifferentworkspace"

#clean up all items in the workspace
fcs = arcpy.ListFeatureClasses()
tabs = arcpy.ListTables()
rasters = arcpy.ListRasters()
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 
### for each FeatClass in the list of fcs's, delete it.
for f in fcs:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.Delete_management(f)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.AddMessage("deleted: " + f)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 
### for each TableClass in the list of tab's, delete it.
for t in tabs:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.Delete_management(t)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.AddMessage("deleted: " + t)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 
### for each Raster in the workspace, delete it
for r in rasters:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.Delete_management(r)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.AddMessage("deleted " + str(r))

&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Post the code you percieve to be too slow for opinions or suggestions on how to improve it.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 21:42:58 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-improve-the-python-efficiency/m-p/493470#M38712</guid>
      <dc:creator>JamesCrandall</dc:creator>
      <dc:date>2021-12-11T21:42:58Z</dc:date>
    </item>
    <item>
      <title>Re: How to improve the python efficiency?</title>
      <link>https://community.esri.com/t5/python-questions/how-to-improve-the-python-efficiency/m-p/493471#M38713</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;

# set the workspace
arcpy.env.workspace = r"C:\pathtomyworkspace"

#set a different workspace
arcpy.env.workspace = r"C:\pathtomydifferentworkspace"

#clean up all items in the workspace
fcs = arcpy.ListFeatureClasses()
tabs = arcpy.ListTables()
rasters = arcpy.ListRasters()
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 
### for each FeatClass in the list of fcs's, delete it.
for f in fcs:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.Delete_management(f)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.AddMessage("deleted: " + f)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 
### for each TableClass in the list of tab's, delete it.
for t in tabs:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.Delete_management(t)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.AddMessage("deleted: " + t)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 
### for each Raster in the workspace, delete it
for r in rasters:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.Delete_management(r)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.AddMessage("deleted " + str(r))

&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Post the code you percieve to be too slow for opinions or suggestions on how to improve it.&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thank u for your reply! It's useful!&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;And the code for my third quesion is:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
#After a series process, i get a raster, named myRaster, in Memory (3000 * 2500), whose cellsize is 0.25 * 0.25
path = r"C:\path"
myRaster.save(path+"\\raster" )
&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;it need take a long time to execute! I don't know why!&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 21:43:00 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-improve-the-python-efficiency/m-p/493471#M38713</guid>
      <dc:creator>ZuoqiChen</dc:creator>
      <dc:date>2021-12-11T21:43:00Z</dc:date>
    </item>
    <item>
      <title>Re: How to improve the python efficiency?</title>
      <link>https://community.esri.com/t5/python-questions/how-to-improve-the-python-efficiency/m-p/493472#M38714</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hi Zuoqi,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Try executing the following:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;import arcpy
from arcpy.sa import *

arcpy.CheckOutExtension("Spatial")

myRaster = CreateRandomRaster(100, 0.25, Extent(0, 0, 750, 625))
path = r"C:\path"
myRaster.save(path+"\\raster" )&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;How long does it take to execute?&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 21:43:03 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-improve-the-python-efficiency/m-p/493472#M38714</guid>
      <dc:creator>JakeSkinner</dc:creator>
      <dc:date>2021-12-11T21:43:03Z</dc:date>
    </item>
    <item>
      <title>Re: How to improve the python efficiency?</title>
      <link>https://community.esri.com/t5/python-questions/how-to-improve-the-python-efficiency/m-p/493473#M38715</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;Hi Zuoqi,&lt;BR /&gt;&lt;BR /&gt;Try executing the following:&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;import arcpy
from arcpy.sa import *

arcpy.CheckOutExtension("Spatial")

myRaster = CreateRandomRaster(100, 0.25, Extent(0, 0, 750, 625))
path = r"C:\path"
myRaster.save(path+"\\raster" )&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;How long does it take to execute?&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;it takes less than 30 sec.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 21:43:05 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-improve-the-python-efficiency/m-p/493473#M38715</guid>
      <dc:creator>ZuoqiChen</dc:creator>
      <dc:date>2021-12-11T21:43:05Z</dc:date>
    </item>
    <item>
      <title>Re: How to improve the python efficiency?</title>
      <link>https://community.esri.com/t5/python-questions/how-to-improve-the-python-efficiency/m-p/493474#M38716</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;It looks like it isn't the saving of the raster that is taking a long time, but the series of processes executed beforehand.&amp;nbsp; Can you post your entire script?&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 27 Aug 2013 15:28:23 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-improve-the-python-efficiency/m-p/493474#M38716</guid>
      <dc:creator>JakeSkinner</dc:creator>
      <dc:date>2013-08-27T15:28:23Z</dc:date>
    </item>
    <item>
      <title>Re: How to improve the python efficiency?</title>
      <link>https://community.esri.com/t5/python-questions/how-to-improve-the-python-efficiency/m-p/493475#M38717</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;It looks like it isn't the saving of the raster that is taking a long time, but the series of processes executed beforehand.&amp;nbsp; Can you post your entire script?&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;I use breakpoint to test the code.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;There is not problems in the series of processes executed beforehand. &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;I can't give u my code, because of confidentiality agreement. But I can describe my code details.&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
#Create an empty Raster in Memory
myRaster = Raster(dsm_file)*0
for i in (0,10):
&amp;nbsp;&amp;nbsp;&amp;nbsp; #Execute HillShade
&amp;nbsp;&amp;nbsp;&amp;nbsp; #myHillShadePath is the output Path and file name for HillShade
&amp;nbsp;&amp;nbsp;&amp;nbsp; myHillShadePath = r"C:/data/hillshade_"+str(i)
&amp;nbsp;&amp;nbsp;&amp;nbsp; myHill = Execute_HillShade(myHillShadePath )
&amp;nbsp;&amp;nbsp;&amp;nbsp; myRaster = Execute_Raster(myHill ,myRaster )
&amp;nbsp;&amp;nbsp;&amp;nbsp; #clean up the HillShade
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.Delete_management(outHillShadeRaster)

#save the final raster
myRaster.save(path)
&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;if i do not clean up the HillShade raster, which means i delete the&amp;nbsp; "arcpy.Delete_management(outHillShadeRaster)" ,&amp;nbsp; the program can be work.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;if i clean up the HillShade raster, the program will be closed when the program going to output the final data.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 21:43:08 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-improve-the-python-efficiency/m-p/493475#M38717</guid>
      <dc:creator>ZuoqiChen</dc:creator>
      <dc:date>2021-12-11T21:43:08Z</dc:date>
    </item>
  </channel>
</rss>

