[Solved] Finding neighbours of an element in a matrix? [closed]
[ad_1] # 2dMatrix: Your matrix # x: x-coordinate of the element for which you’re searching for neighbors # y: y-coordinate of the element for which you’re searching for neighbors def nearest_elements_2dMatrix(2dMatrix, x,y): upleft = 2dMatrix[x-1][y-1] if (x-1 >= 0 and y-1>=0) else None downleft = 2dMatrix[x-1][y+1] if (x-1 >= 0 and y+1 < len(2dMatrix)) else … Read more