def _graph_connected_component(graph, node_id):
 n_node = graph.shape[0]
 if sparse.issparse(graph):
  graph = graph.tocsr()
 connected_nodes = np.zeros(n_node, dtype=np.bool)
 nodes_to_explore = np.zeros(n_node, dtype=np.bool)
 nodes_to_explore[node_id] = True
 for _ in range(n_node):
  last_num_component = connected_nodes.sum()
  np.logical_or(connected_nodes, nodes_to_explore, out=connected_nodes)
  if (last_num_component >= connected_nodes.sum()):
   break
  indices = np.where(nodes_to_explore)[0]
  nodes_to_explore.fill(False)
  for i in indices:
   if sparse.issparse(graph):
    neighbors = graph[i].toarray().ravel()
   else:
    neighbors = graph[i]
   np.logical_or(nodes_to_explore, neighbors, out=nodes_to_explore)
 return connected_nodes

def _graph_connected_component ( graph , node_id ) : n_node = graph . shape [ 0 ] if sparse . issparse ( graph ) : graph = graph . tocsr ( ) connected_nodes = np . zeros ( n_node , dtype = np . bool ) nodes_to_explore = np . zeros ( n_node , dtype = np . bool ) nodes_to_explore [ node_id ] = True for _ in range ( n_node ) : last_num_component = connected_nodes . sum ( ) np . logical_or ( connected_nodes , nodes_to_explore , out = connected_nodes ) if ( last_num_component >= connected_nodes . sum ( ) ) : break indices = np . where ( nodes_to_explore ) [ 0 ] nodes_to_explore . fill ( False ) for i in indices : if sparse . issparse ( graph ) : neighbors = graph [ i ] . toarray ( ) . ravel ( ) else : neighbors = graph [ i ] np . logical_or ( nodes_to_explore , neighbors , out = nodes_to_explore ) return connected_nodes
find the largest graph connected components that contains one given node parameters graph : array-like .