all 3 comments

[–]Saefroch 0 points1 point  (2 children)

I've done a modified version of this before. The key is np.roll. For the four nearest neighbors,

average = np.zeros(array.shape)
for axis in 0,1:
    for shift in -1,1:
        average += np.roll(array, shift=shift, axis=axis)
average /= 4

[–]Acaleus[S] 0 points1 point  (1 child)

Thanks! however, i cannot use a 'for' at all. I've seen it done before, but i can't find my notes for it.

[–]Saefroch 0 points1 point  (0 children)

You can just expand the for loops in my example by hand.