Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Numpy solution in 3rd party category for Moore Neighbourhood by Pavellver
import numpy as np
def count_neighbours(grid, row, col):
i, j, k, n = 1, 2, 1, 2
if not row:
i = 0
if not col:
k = 0
if row == len(grid)-1:
j = 1
if col == len(grid[0])-1:
n = 1
grid = np.array(grid)
a = grid[row-i:row+j, col-k:col+n]
return a.sum() - grid[row, col]
April 3, 2023
Comments: