def using_eight_shifts(data):
    h, w = data.shape
data2 = np.empty((h + 2, w + 2))
data2[(0, -1), :] = np.nan
data2[:, (0, -1)] = np.nan
data2[1:1 + h, 1:1 + w] = data
result = np.where(np.logical_and.reduce([(data2[i:i + h, j:j + w] == data) for
    i in range(3) for j in range(3) if not (i == 1 and j == 1)]))
return result
Retrieve position of elements with setting some criteria in numpy