The SHIFT function would be helpful here: https://www.l3harrisgeospatial.com/docs/shift.html Here is an example below. Using SHIFT is about 15-20 times faster than your double loop in my testing. ;IDL PRO CODE dim = 4000 ;number of X/Y points in 2D array val = randomn(seed,dim,dim) ;generate random 2D float array sz = size(val) temp = fltarr(sz[1],sz[2]) ;Existing method tic for y = 1, sz[2]-2 DO $ for x = 1,sz[1]-2 DO $ temp[x, y] = TOTAL(ABS(val[x-1:x+1, y-1: y+1] - val[x, y])) toc ;Another method using SHIFT instead tic temp2 = abs(val-shift(val,[1,0]))+abs(val-shift(val,[1,-1]))+abs(val-shift(val,[0,-1]))+abs(val-shift(val,[-1,-1]))+abs(val-shift(val,[-1,0]))+abs(val-shift(val,[-1,1]))+ $ abs(val-shift(val,[0,1]))+abs(val-shift(val,[1,1])) toc ---- IDL Prints: % Time elapsed: 9.2260001 seconds. % Time elapsed: 0.51099992 seconds. There might be some further room for improvement using
|