Extracting the elements matching the filter
问题 I want to filter the indices whose footprint (3,3) consists of 1s. import numpy as np data = np.array([[1, 1 , 0 , 0 , 0 , 0 , 1 , 0], [1, 1 , 1 , 0 , 0 , 1 , 1 , 0], [1, 1 , 1 , 1 , 1 , 0 , 0 , 0], [0, 0 , 1 , 1 , 1 , 0 , 0 , 0], [0, 0 , 1 , 1 , 1 , 1 , 0 , 1], [1, 1 , 0 , 0 , 0 , 1 , 1 , 1], [1, 1 , 0 , 0 , 0 , 1 , 1 , 1]]) The expected answer is below, unwanted positions are set to 0s: answer = np.array([[0, 0 , 0 , 0 , 0 , 0 , 0 , 0], [0, 0 , 0 , 0 , 0 , 0 , 0 , 0], [0, 0 , 1 , 1 , 1 , 0