Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
connected_components solution in 3rd party category for Calculate Islands by gyahun_dash
from collections import Counter
from scipy import argwhere, array
from scipy.linalg import norm
from scipy.sparse.csgraph import connected_components
def checkio(data):
nodes = argwhere(array(data) == 1)
edges = array([[int(norm(m - n) < 2) for m in nodes] for n in nodes])
ccs, labels = connected_components(edges, return_labels=True)
return sorted(Counter(labels).values())
Jan. 6, 2017
Comments: