2016-04-13 20 views

答えて

0

は、だから私は

def as_spanning_trees(G): 
    """ 
    For a given graph with multiple sub graphs, find the components 
    and draw a spanning tree. 

    Returns a new Graph with components as spanning trees (i.e. without cycles). 

    Parameters 
    --------- 
    G:  - networkx.Graph 
    """ 

    G2 = nx.Graph() 
    # We find the connected constituents of the graph as subgraphs 
    graphs = nx.connected_component_subgraphs(G, copy=False) 

    # For each of these graphs we extract the spanning tree, removing the cycles 
    for g in graphs: 
     T = nx.minimum_spanning_tree(g) 
     G2.add_edges_from(T.edges()) 
     G2.add_nodes_from(T.nodes()) 

    return G2 
+1

'T = nx.minimum_spanning_tree(G)'あなたに同じ結果を与えるになってしまいました。 – Aric

+0

ああ、私は本当にドキュメントを読んだことがあります。 – JoelKuiper

関連する問題