If I get it right, you can easily achieve this by using scipy.ndimage
module. Like this:
import numpy as np
from scipy.ndimage import label, find_objects
DashBoard = np.zeros((10,10), dtype=int)
DashBoard[5,5] = 1
DashBoard[5,4] = 1
DashBoard[5,6] = 1
DashBoard[6,6] = 1
DashBoard[7,7] = 1
print(DashBoard)
initial Dashboard. note the "alien" at (7,7)
# define which neighbours count as adjacent (in this case, exclude diagonals)
s = [[0,1,0],
[1,1,1],
[0,1,0]]
# label adjacent "islands"
labeled, nums = label(DashBoard, structure=s)
print(nums)
print(labeled)
labeled visualized:
loc = find_objects(labeled)[0]
res = labeled[loc]
res visualized:
print(res.T.shape)
will give you
(3, 2)