Answers for "how to find the neighbors of an element in matrix python"

1

how to find the neighbors of an element in matrix python

mat = "NxN matrix"
a, b = (2, 3) # the index of the element 
neighbors = [mat[i][j] for i in range(a-1, a+2) for j in range(b-1, b+2) if i > -1 and j > -1 and j < len(mat[0]) and i < len(mat)]
Posted by: Guest on October-23-2021

Code answers related to "how to find the neighbors of an element in matrix python"

Python Answers by Framework

Browse Popular Code Answers by Language