Excluding the boundary zero values, is it possible to group the coordinates (as tuples) of remaining zero values into different lists in this numpy array?
[[ 0 0 0 0 0 0 0 0 0 0 0]
[ 0 1 1 1 0 0 0 1 10 2 0]
[ 0 2 10 2 1 0 0 1 2 10 0]
[ 0 10 3 10 1 0 0 0 1 1 0]
[ 0 1 2 1 1 0 0 0 0 0 0]
[ 0 1 2 1 2 2 2 1 0 0 0]
[ 0 10 2 10 2 10 10 1 0 0 0]
[ 0 1 2 1 2 2 2 1 1 1 0]
[ 0 0 0 0 0 0 0 0 1 10 0]
[ 0 0 0 0 0 0 0 0 1 1 0]
[ 0 0 0 0 0 0 0 0 0 0 0]]
for ex. in above grid, there are two 'groups' of zeros, one in lower left corner and other in upper right corner. can these be put into separate lists, for every such matrix generated? Below is the code for creating matrix 'sol_mat' :-
import numpy as np
import random
bomb_mat = np.zeros((11,11), dtype = int)
for i in range(10):
a = random.randint(1,9)
b = random.randint(1,9)
bomb_mat[a,b] = 1
sol_mat = np.zeros(11,11), dtype = int)
for j in range(1,10):
for k in range(1,y-1):
if bomb_mat[j,k] == 1:
sol_mat[j,k] = 10
else:
sol_mat[j,k] = bomb_mat[j-1,k-1] + bomb_mat[j,k-1] + bomb_mat[j+1,k-1]+ bomb_mat[j-1,k] + bomb_mat[j+1,k] + bomb_mat[j-1,k+1] + bomb_mat[j,k+1] + bomb_mat[j+1,k+1]
Trying to create minesweeper