def _graph_is_connected(graph):
 if sparse.isspmatrix(graph):
  (n_connected_components, _) = connected_components(graph)
  return (n_connected_components == 1)
 else:
  return (_graph_connected_component(graph, 0).sum() == graph.shape[0])

def _graph_is_connected ( graph ) : if sparse . isspmatrix ( graph ) : ( n_connected_components , _ ) = connected_components ( graph ) return ( n_connected_components == 1 ) else : return ( _graph_connected_component ( graph , 0 ) . sum ( ) == graph . shape [ 0 ] )
return whether the graph is connected or not parameters graph : array-like or sparse matrix .