def largest_connected_component(matrix):
    """Compute the adjacency matrix of the largest connected component of the
    graph whose input matrix is adjacent.
    """

    try:
        import scipy.sparse
        n, components = scipy.sparse.csgraph.connected_components(
            matrix, directed=False)
        print("I found " + str(n) + " connected components.")
        component_dist = collections.Counter(components)
        print("Distribution of components: " + str(component_dist))
        most_common, _ = component_dist.most_common(1)[0]
        ilcc = (components == most_common)
        return matrix[:, ilcc][ilcc]

    except ImportError as e:
        print("I couldn't find scipy which is needed for graph routines.")
        print(str(e))
        print("Returning input matrix as fallback.")
        return matrix
def largest_connected_component ( matrix ) : try : import scipy . sparse n , components = scipy . sparse . csgraph . connected_components ( matrix , directed = False ) print ( "I found " + str ( n ) + " connected components." ) component_dist = collections . Counter ( components ) print ( "Distribution of components: " + str ( component_dist ) ) most_common , _ = component_dist . most_common ( 1 ) [ 0 ] ilcc = ( components == most_common ) return matrix [ : , ilcc ] [ ilcc ] except ImportError as e : print ( "I couldn't find scipy which is needed for graph routines." ) print ( str ( e ) ) print ( "Returning input matrix as fallback." ) return matrix
Compute the adjacency matrix of the largest connected component of the
    graph whose input matrix is adjacent.