There's a shape inconsistency in compute_neighbours function:
def compute_neighbours(Z):
shape = len(Z), len(Z[0])
N = [[0,]*(shape[0]) for i in range(shape[1])]
for x in range(1,shape[0]-1):
for y in range(1,shape[1]-1):
N[x][y] = Z[x-1][y-1]+Z[x][y-1]+Z[x+1][y-1] \
+ Z[x-1][y] +Z[x+1][y] \
+ Z[x-1][y+1]+Z[x][y+1]+Z[x+1][y+1]
return N
Shape of N is currently a transposed shape of Z, which would result in index of out range exception in case of non-square field.
Not critical for the example, but a bit confusing anyway.
There's a shape inconsistency in
compute_neighbours
function:Shape of
N
is currently a transposed shape ofZ
, which would result inindex of out range
exception in case of non-square field.Not critical for the example, but a bit confusing anyway.