My previous reply was basically the answer.
Set the initial maximum to
Then on line four set maximum to the adjacent you are checking
On line five set
for y, x in inp2: # set maximum to the current value for dy, dx in ADJACENTS: if 0 <= y+dy < P and 0 <= x+dx < Q: # set maximum to adjacent value if higher than current maximum # set the location in the new array to the maximumJust replace the lines. You still index into inp1 with the coordinates (x, y, x+dx, y+dy).
Set the initial maximum to
inp1[y,x]
Then on line four set maximum to the adjacent you are checking
inp1[y+dy, x+dx]
if that is higher than current maximum.On line five set
inp_new[y,x]
to the maximum.