Hi GeoNet community,

I have a little bit of problem in my code. I have a raster list from 0-365 representing day of year (doy1-doy366). I would like to calculate the mean of my rasters using the last three rasters (these are raster364, raster365, raster366, which are indexed as 363,364,365) and the first three rasters of my list (raster1, raster2, and raster3, which are indexed as 0, 1, 2).

this is my initial code:

rasters = arcpy.ListRasters("*", "tif") last3 = range(363,366) first3 = range(0,3) lastdek = (last5, first1) lastDekad = [] # process only the 6 rasters - last and first three rasters for l in range(0,7): print l lastDekad.append(rasters[l]) dek37 = CellStatistics(lastDekad, "MEAN", "NODATA") output = 'E:/Test/Temp/tmax_dek_037.tif' dek37.save(output)

Any help is much appreciated.

Hope my query is clear.

Thanks,

-Leo

as a possible demo, examine this idea...

>>> aList = [i for i in range(366)]

>>> aList

[0, 1, 2, 3, .... 360, 361, 362, 363, 364, 365] #a big snip here

>>> bList = [aList[i] for i in range(-3,3)]

>>> bList

[363, 364, 365, 0, 1, 2]

>>>

will at least give you some ideas on accessing the head and tail of a list