<?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 How to save every iteration's output from a double for loop in arcpy in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/how-to-save-every-iteration-s-output-from-a-double/m-p/1003806#M59105</link>
    <description>&lt;P&gt;&lt;STRONG&gt;Hello, everyone. I have two sets of similar kind of rasters (1st set: idwlist, 2nd set: equallist) and I want to multiply each raster from the 1st group (‘eachidw’) with every raster from the 2nd group (‘eachequal’). In other words, I want to create a code that calculates and stores all the possible products (multiplications) between the rasters of the two groups.&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&amp;nbsp;&lt;/STRONG&gt;&lt;STRONG&gt;The problem with the arcpy code below is that the output of every iteration is not saved but overwritten, so I would like to ask if there is any way to make the code save each multiplication output. Thanks a lot !&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;from arcpy import env&lt;/P&gt;&lt;P&gt;from arcpy.sa import *&lt;/P&gt;&lt;P&gt;import os&lt;/P&gt;&lt;P&gt;arcpy.env.workspace = "C:/MSc_thesis/XrApor"&lt;/P&gt;&lt;P&gt;idwlist&amp;nbsp; = arcpy.ListRasters("*", "TIF")&lt;/P&gt;&lt;P&gt;equallist = arcpy.ListRasters("*", "GRID")&lt;/P&gt;&lt;P&gt;for eachidw in idwlist:&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;for eachequal in equallist:&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; outTimes = Times(eachidw,eachequal)&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;.&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;outTimes.save("C:/MSc_thesis/products")&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Sun, 22 Nov 2020 21:28:52 GMT</pubDate>
    <dc:creator>CamiSunley</dc:creator>
    <dc:date>2020-11-22T21:28:52Z</dc:date>
    <item>
      <title>How to save every iteration's output from a double for loop in arcpy</title>
      <link>https://community.esri.com/t5/python-questions/how-to-save-every-iteration-s-output-from-a-double/m-p/1003806#M59105</link>
      <description>&lt;P&gt;&lt;STRONG&gt;Hello, everyone. I have two sets of similar kind of rasters (1st set: idwlist, 2nd set: equallist) and I want to multiply each raster from the 1st group (‘eachidw’) with every raster from the 2nd group (‘eachequal’). In other words, I want to create a code that calculates and stores all the possible products (multiplications) between the rasters of the two groups.&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&amp;nbsp;&lt;/STRONG&gt;&lt;STRONG&gt;The problem with the arcpy code below is that the output of every iteration is not saved but overwritten, so I would like to ask if there is any way to make the code save each multiplication output. Thanks a lot !&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;from arcpy import env&lt;/P&gt;&lt;P&gt;from arcpy.sa import *&lt;/P&gt;&lt;P&gt;import os&lt;/P&gt;&lt;P&gt;arcpy.env.workspace = "C:/MSc_thesis/XrApor"&lt;/P&gt;&lt;P&gt;idwlist&amp;nbsp; = arcpy.ListRasters("*", "TIF")&lt;/P&gt;&lt;P&gt;equallist = arcpy.ListRasters("*", "GRID")&lt;/P&gt;&lt;P&gt;for eachidw in idwlist:&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;for eachequal in equallist:&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; outTimes = Times(eachidw,eachequal)&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;.&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;outTimes.save("C:/MSc_thesis/products")&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 22 Nov 2020 21:28:52 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-save-every-iteration-s-output-from-a-double/m-p/1003806#M59105</guid>
      <dc:creator>CamiSunley</dc:creator>
      <dc:date>2020-11-22T21:28:52Z</dc:date>
    </item>
    <item>
      <title>Re: How to save every iteration's output from a double for loop in arcpy</title>
      <link>https://community.esri.com/t5/python-questions/how-to-save-every-iteration-s-output-from-a-double/m-p/1003811#M59106</link>
      <description>&lt;P&gt;Logically you would want to save the output file as a combination of the names of the rasters.&lt;/P&gt;&lt;P&gt;I'd grab the names of the rasters before you multiple them, and create a path from that combination.&lt;/P&gt;&lt;P&gt;ensure you import the os module (import os)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;from arcpy import env

from arcpy.sa import *

import os

arcpy.env.workspace = "C:/MSc_thesis/XrApor"

idwlist  = arcpy.ListRasters("*", "TIF")

equallist = arcpy.ListRasters("*", "GRID")

for eachidw in idwlist:

    for eachequal in equallist:

        out_name = eachidw.name + "_" + eachequal.name

        out_path = os.path.join(r"C:/MSc_thesis/products", out_name)

        outTimes = Times(eachidw,eachequal)          

        outTimes.save(out_path)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 22 Nov 2020 21:45:16 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-save-every-iteration-s-output-from-a-double/m-p/1003811#M59106</guid>
      <dc:creator>DavidPike</dc:creator>
      <dc:date>2020-11-22T21:45:16Z</dc:date>
    </item>
    <item>
      <title>Re: How to save every iteration's output from a double for loop in arcpy</title>
      <link>https://community.esri.com/t5/python-questions/how-to-save-every-iteration-s-output-from-a-double/m-p/1003821#M59107</link>
      <description>&lt;LI-CODE lang="python"&gt;for i, eachidw in enumerate(idwlist):
     for j, eachequal in enumerate(equallist):
          outTimes = Times(eachidw,eachequal)
          nme = "C:/MSc_thesis/products/" + "raster_{}_{}".format(i, j)
.         outTimes.save(nme)&lt;/LI-CODE&gt;&lt;P&gt;in its simplest form.&amp;nbsp; Now if you need the actual names and eachidw and eachequal are short names and not full paths, you can replace, i, j in the format section&lt;/P&gt;</description>
      <pubDate>Sun, 22 Nov 2020 22:17:44 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-save-every-iteration-s-output-from-a-double/m-p/1003821#M59107</guid>
      <dc:creator>DanPatterson</dc:creator>
      <dc:date>2020-11-22T22:17:44Z</dc:date>
    </item>
    <item>
      <title>Re: How to save every iteration's output from a double for loop in arcpy</title>
      <link>https://community.esri.com/t5/python-questions/how-to-save-every-iteration-s-output-from-a-double/m-p/1003837#M59108</link>
      <description>I really appreciate your response. Since I am a beginner in python I am not sure if I replace correctly the elements eachidw.name and eachequal.name you use in the code. Should I use the full path of the first rasters respectively or sth else ? Which is the proper format ? Thanks.</description>
      <pubDate>Sun, 22 Nov 2020 23:20:07 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-save-every-iteration-s-output-from-a-double/m-p/1003837#M59108</guid>
      <dc:creator>CamiSunley</dc:creator>
      <dc:date>2020-11-22T23:20:07Z</dc:date>
    </item>
    <item>
      <title>Re: How to save every iteration's output from a double for loop in arcpy</title>
      <link>https://community.esri.com/t5/python-questions/how-to-save-every-iteration-s-output-from-a-double/m-p/1003841#M59109</link>
      <description>&lt;P&gt;I tried your suggestion and it works. That was really helpful, thank you very much.&lt;/P&gt;</description>
      <pubDate>Mon, 23 Nov 2020 00:03:00 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-save-every-iteration-s-output-from-a-double/m-p/1003841#M59109</guid>
      <dc:creator>CamiSunley</dc:creator>
      <dc:date>2020-11-23T00:03:00Z</dc:date>
    </item>
  </channel>
</rss>

