One option would be to use a SQL statement within a Con function. The following example performs the following actions:
- Generate a SQL expression from a list of values. Doing this in an
automated fashion is important for long lists of values.
- Use Con to perform an if/else evaluation on a raster. In this case,
all values in the list will be assigned "1" and all others "0".
import arcpy
from arcpy import env
from arcpy.sa import *
arcpy.CheckOutExtension = "Spatial"
vals = [1,2,4,8,16,32,64,128]
inRaster = r'C:\temp\example.tif'
new = []
# Generate a SQL expression from the "vals" list
for i in vals:
new.append("value " + "= " + str(i) + " OR ")
expression = ''.join(new)[:-4]
# Use Con to convert all raster values from the "vals" list to 1 and all others to 0
outCon = Con(inRaster, 1, 0, expression)
outCon.save("C:/temp/revisedRaster.tif")