For the given 2d array of data, how to retrieve the position (index) of 7 and 11 in the bold. Because only they are the elements surrounded by same value in the neighbours>
displacements = [[-1, -1], [-1, 0], [-1, 1], [0, -1], [0, 1], [1, -1], [1, 0], [1, 1]]
for x in range(1, data.shape[0] - 1):
for y in range(1, data.shape[1] - 1):
if all((data[x][y] == data[x + a][y + b]) for a, b in displacements):
print np.array([x, y], dtype=np.int64)
Not as succint as the other answers, but it's clear and prints the correct output. I think it's also a little easier to change/add displacement values.
Whoops, didn't realize you wanted all 8 neighbors. Easy fix though. :)