79712503

Date: 2025-07-23 20:08:16
Score: 0.5
Natty:
Report link

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) enter image description here

# 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:

enter image description here

loc = find_objects(labeled)[0]
res = labeled[loc]

res visualized:

enter image description here

print(res.T.shape)

will give you

(3, 2)

Reasons:
  • Probably link only (1):
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Low reputation (0.5):
Posted by: strawdog