If inputed an numpy 2d array such as
100 100 100 100 100
100 0 0 0 100
100 0 0 0 100
100 0 0 0 100
100 100 100 100 100
an output like this should be obtained
100 100 100 100 100
100 50 25 50 100
100 25 0 25 100
100 50 25 50 100
100 100 100 100 100
where every number except the border becomes the mean of its adjacent numbers.
My current code works but I need to use it without for loops and vectorize it using numpy.
My current code:
import numpy as np
def evolve_heat_slow(u):
u2 = np.copy(u)
x=u2.shape[0]
y=u2.shape[1]
for i in range(1,x-1):
for s in range(1,y-1):
u2[i,s]=(u[i-1,s]+u[i+1,s]+u[i,s+1]+u[i,s-1])/4
return u2