# Iterating raster pairs using ArcPy? [closed]

I have a problem that must be solved in automatic manner. I am using ArcGIS 10.2.

I have a raster files that I have to pair and then make the calculation. I have tried to use ModelBuilder but there is not possible to use two iterations. I have made submodel but then it did not pair the layers correctly.

THe calculation on the pairs is simple. Just minus them than the results must be divided by the maximum value from the resulted layer.

I have :

raster1_yearA, raster1_yearB, raster1_yearC, raster1_yearD
raster2_yearA, raster2_yearB, raster2_yearC, raster2_yearD

But I have to make pairs lik this:

raster1_yearA - raster1_yearB
raster1_yearA - raster1_yearC
raster1_yearA - raster1_yearD

## closed as off-topic by PolyGeo♦Feb 20 '18 at 11:28

This question appears to be off-topic. The users who voted to close gave this specific reason:

• "Questions seeking help to debug/write/improve code must include the desired behavior, a specific problem or error and the shortest code necessary to reproduce it in the question itself. Providing a clear problem statement and evidence of a code attempt will help others to help you. See: How to create a Minimal, Complete, and Verifiable example." – PolyGeo
If this question can be reworded to fit the rules in the help center, please edit the question.

To get started with a Python script you can try code below. ListRasters will sort your rasters by name so if they are named like you say, it should work. Otherwise there are other ways of sorting the list.

``````import arcpy
from arcpy.sa import *
from itertools import izip

folder = r'C:\Test\Rasters' #Or geodatabase. Change to match your data.
arcpy.env.workspace = folder

#Function which return 4 items at a time from list
def fourwise(iterable):
a = iter(iterable)
return izip(a, a, a, a)

for a, b, c, d in fourwise(arcpy.ListRasters()):
outMinus1 = Minus(a,b)
outMinus2 = Minus(a,c)
outMinus3 = Minus(a,d)
#... do something else with outMinuses...
``````

To list rasters, you would need to use the `arcpy.ListRasters()` function. Then you would need to use the `for` loop with the `Minus` GP tool.