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