I want to take a certain size of matrix(2 X 2 X 2) in overall matrix(whatever size), and want to check whether certain size of matrix (test matrix) has some elements(i.e. 1 or 2), however, I don't know how to check, easily. I just wrote the code as shown below. In my view, there are some way to be optimized. Please give me some helpful advice. Thanks!
def labeling(input_matrix)
test_matrix = np.zeros((2,2,2))
for i in input_matrix.shape[0]
for j in input_matrix.shape[1]
for k in input_matrix.shape[2]
test_matrix[i,j,k] = input_matrix[i,j,k]
test_matrix[i+1,j,k] = input_matrix[i+1,j,k]
test_matrix[i,j+1,k] = input_matrix[i,j+1,k]
test_matrix[i+1,j+1,k] = input_matrix[i+1,j+1,k]
test_matrix[i,j,k+1] = input_matrix[i,j,k+1]
test_matrix[i+1,j,k+1] = input_matrix[i+1,j,k+1]
test_matrix[i,j+1,k+1] = input_matrix[i,j+1,k+1]
test_matrix[i+1,j+1,k+1] = input_matrix[i+1,j+1,k+1]
For example, this is what I expected in 2D.
input field = [0 0 0;
1 2 1;
3 0 2]
check matrix in unit of 2 * 2.
1) [0 0;
1 2] there is no 1 & 2 & 3. -> pass
2) [0 0;
2 1] there is no 1 & 2 & 3. -> pass
3) [1 2; [4 4;
3 0] there is 1 & 2 & 3 -> make this 4 4]
output_field = [0 0 0;
4 4 1;
4 4 2]