def spectral_ordering(G, weight='weight', normalized=False, tol=1e-08, method='tracemin'):
 if (len(G) == 0):
  raise nx.NetworkXError('graph is empty.')
 G = _preprocess_graph(G, weight)
 find_fiedler = _get_fiedler_func(method)
 order = []
 for component in nx.connected_components(G):
  size = len(component)
  if (size > 2):
   L = nx.laplacian_matrix(G, component)
   x = (None if (method != 'lobpcg') else _rcm_estimate(G, component))
   fiedler = find_fiedler(L, x, normalized, tol)[1]
   order.extend((u for (x, c, u) in sorted(zip(fiedler, range(size), component))))
  else:
   order.extend(component)
 return order

def spectral_ordering ( G , weight = 'weight' , normalized = False , tol = 1e-08 , method = 'tracemin' ) : if ( len ( G ) == 0 ) : raise nx . NetworkXError ( 'graph is empty.' ) G = _preprocess_graph ( G , weight ) find_fiedler = _get_fiedler_func ( method ) order = [ ] for component in nx . connected_components ( G ) : size = len ( component ) if ( size > 2 ) : L = nx . laplacian_matrix ( G , component ) x = ( None if ( method != 'lobpcg' ) else _rcm_estimate ( G , component ) ) fiedler = find_fiedler ( L , x , normalized , tol ) [ 1 ] order . extend ( ( u for ( x , c , u ) in sorted ( zip ( fiedler , range ( size ) , component ) ) ) ) else : order . extend ( component ) return order
compute the spectral_ordering of a graph .