Skip to content Skip to sidebar Skip to footer

Calculate Pixel By Pixel Mean Of The Rasters Using Numpy

Since the two rasters (raster1 and raster2) overlap each other, I want to make new raster by calculating mean of each overlapped pixels; i.e., The resulting new raster is calculat

Solution 1:

Maybe I misunderstood you but do you want?

raster = (raster1 + raster2) / 2

Actually in this case you don't even need np.mean, just use matrix operations.

np.mean is used to deal with calculating mean for a single matrix on specific axis, so it is a different situation.

Solution 2:

It should be

new = np.mean([raster1,raster2],axis=1)

with brackets. Actually I am guessing it should be It should be

new = np.mean([raster1,raster2],axis=0)

The first argument to np.mean should be the whole array, see e.g. http://wiki.scipy.org/Numpy_Example_List_With_Doc#mean

Post a Comment for "Calculate Pixel By Pixel Mean Of The Rasters Using Numpy"