def flow_hierarchy(G, weight=None):
 if (not G.is_directed()):
  raise nx.NetworkXError('G must be a digraph in flow_heirarchy')
 scc = nx.strongly_connected_components(G)
 return (1.0 - (sum((G.subgraph(c).size(weight) for c in scc)) / float(G.size(weight))))

def flow_hierarchy ( G , weight = None ) : if ( not G . is_directed ( ) ) : raise nx . NetworkXError ( 'G must be a digraph in flow_heirarchy' ) scc = nx . strongly_connected_components ( G ) return ( 1.0 - ( sum ( ( G . subgraph ( c ) . size ( weight ) for c in scc ) ) / float ( G . size ( weight ) ) ) )
returns the flow hierarchy of a directed network .