Python networkx.number_of_edges() Examples
The following are 26
code examples of networkx.number_of_edges().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
networkx
, or try the search function
.
Example #1
Source File: test_atlas.py From aws-kube-codesuite with Apache License 2.0 | 6 votes |
def test_nondecreasing_degree_sequence(self): # Check for lexicographically nondecreasing degree sequences # (for fixed number of nodes and edges). # # There are three exceptions to this rule in the order given in # the "Atlas of Graphs" book, so we need to manually exclude # those. exceptions = [('G55', 'G56'), ('G1007', 'G1008'), ('G1012', 'G1013')] for n, group in groupby(self.GAG, key=nx.number_of_nodes): for m, group in groupby(group, key=nx.number_of_edges): for G1, G2 in pairwise(group): if (G1.name, G2.name) in exceptions: continue d1 = sorted(d for v, d in G1.degree()) d2 = sorted(d for v, d in G2.degree()) assert_less_equal(d1, d2)
Example #2
Source File: historical_tests.py From qgisSpaceSyntaxToolkit with GNU General Public License v3.0 | 6 votes |
def test_iterators(self): G=self.G() G.add_edges_from([('A', 'B'), ('A', 'C'), ('B', 'D'), ('C', 'B'), ('C', 'D')]) G.add_nodes_from('GJK') assert_equal(sorted(G.nodes_iter()), ['A', 'B', 'C', 'D', 'G', 'J', 'K']) assert_edges_equal(G.edges_iter(), [('A', 'B'), ('A', 'C'), ('B', 'D'), ('C', 'B'), ('C', 'D')]) assert_equal(sorted([v for k,v in G.degree_iter()]), [0, 0, 0, 2, 2, 3, 3]) assert_equal(sorted(G.degree_iter(),key=str), [('A', 2), ('B', 3), ('C', 3), ('D', 2), ('G', 0), ('J', 0), ('K', 0)]) assert_equal(sorted(G.neighbors_iter('A')),['B', 'C']) assert_raises(nx.NetworkXError,G.neighbors_iter,'X') G.clear() assert_equal(nx.number_of_nodes(G),0) assert_equal(nx.number_of_edges(G),0)
Example #3
Source File: historical_tests.py From aws-kube-codesuite with Apache License 2.0 | 6 votes |
def test_iterators(self): G = self.G() G.add_edges_from([('A', 'B'), ('A', 'C'), ('B', 'D'), ('C', 'B'), ('C', 'D')]) G.add_nodes_from('GJK') assert_equal(sorted(G.nodes()), ['A', 'B', 'C', 'D', 'G', 'J', 'K']) assert_edges_equal(G.edges(), [('A', 'B'), ('A', 'C'), ('B', 'D'), ('C', 'B'), ('C', 'D')]) assert_equal(sorted([v for k, v in G.degree()]), [0, 0, 0, 2, 2, 3, 3]) assert_equal(sorted(G.degree(), key=str), [('A', 2), ('B', 3), ('C', 3), ('D', 2), ('G', 0), ('J', 0), ('K', 0)]) assert_equal(sorted(G.neighbors('A')), ['B', 'C']) assert_raises(nx.NetworkXError, G.neighbors, 'X') G.clear() assert_equal(nx.number_of_nodes(G), 0) assert_equal(nx.number_of_edges(G), 0)
Example #4
Source File: test_atlas.py From Carnets with BSD 3-Clause "New" or "Revised" License | 6 votes |
def test_nondecreasing_degree_sequence(self): # Check for lexicographically nondecreasing degree sequences # (for fixed number of nodes and edges). # # There are three exceptions to this rule in the order given in # the "Atlas of Graphs" book, so we need to manually exclude # those. exceptions = [('G55', 'G56'), ('G1007', 'G1008'), ('G1012', 'G1013')] for n, group in groupby(self.GAG, key=nx.number_of_nodes): for m, group in groupby(group, key=nx.number_of_edges): for G1, G2 in pairwise(group): if (G1.name, G2.name) in exceptions: continue d1 = sorted(d for v, d in G1.degree()) d2 = sorted(d for v, d in G2.degree()) assert_less_equal(d1, d2)
Example #5
Source File: historical_tests.py From Carnets with BSD 3-Clause "New" or "Revised" License | 6 votes |
def test_iterators(self): G = self.G() G.add_edges_from([('A', 'B'), ('A', 'C'), ('B', 'D'), ('C', 'B'), ('C', 'D')]) G.add_nodes_from('GJK') assert_equal(sorted(G.nodes()), ['A', 'B', 'C', 'D', 'G', 'J', 'K']) assert_edges_equal(G.edges(), [('A', 'B'), ('A', 'C'), ('B', 'D'), ('C', 'B'), ('C', 'D')]) assert_equal(sorted([v for k, v in G.degree()]), [0, 0, 0, 2, 2, 3, 3]) assert_equal(sorted(G.degree(), key=str), [('A', 2), ('B', 3), ('C', 3), ('D', 2), ('G', 0), ('J', 0), ('K', 0)]) assert_equal(sorted(G.neighbors('A')), ['B', 'C']) assert_raises(nx.NetworkXError, G.neighbors, 'X') G.clear() assert_equal(nx.number_of_nodes(G), 0) assert_equal(nx.number_of_edges(G), 0)
Example #6
Source File: test_atlas.py From Carnets with BSD 3-Clause "New" or "Revised" License | 5 votes |
def test_sizes(self): G = self.GAG[0] assert_equal(G.number_of_nodes(), 0) assert_equal(G.number_of_edges(), 0) G = self.GAG[7] assert_equal(G.number_of_nodes(), 3) assert_equal(G.number_of_edges(), 3)
Example #7
Source File: test_atlas.py From aws-kube-codesuite with Apache License 2.0 | 5 votes |
def test_nondecreasing_edges(self): # check for nondecreasing number of edges (for fixed number of # nodes) for n, group in groupby(self.GAG, key=nx.number_of_nodes): for m1, m2 in pairwise(map(nx.number_of_edges, group)): assert_less_equal(m2, m1 + 1)
Example #8
Source File: test_atlas.py From aws-kube-codesuite with Apache License 2.0 | 5 votes |
def test_sizes(self): G = self.GAG[0] assert_equal(G.number_of_nodes(), 0) assert_equal(G.number_of_edges(), 0) G = self.GAG[7] assert_equal(G.number_of_nodes(), 3) assert_equal(G.number_of_edges(), 3)
Example #9
Source File: test_function.py From aws-kube-codesuite with Apache License 2.0 | 5 votes |
def test_number_of_edges(self): assert_equal(self.G.number_of_edges(), nx.number_of_edges(self.G)) assert_equal(self.DG.number_of_edges(), nx.number_of_edges(self.DG))
Example #10
Source File: historical_tests.py From aws-kube-codesuite with Apache License 2.0 | 5 votes |
def test_order_size(self): G = self.G() G.add_edges_from([('A', 'B'), ('A', 'C'), ('B', 'D'), ('C', 'B'), ('C', 'D')]) assert_equal(G.order(), 4) assert_equal(G.size(), 5) assert_equal(G.number_of_edges(), 5) assert_equal(G.number_of_edges('A', 'B'), 1) assert_equal(G.number_of_edges('A', 'D'), 0)
Example #11
Source File: test_atlas.py From Carnets with BSD 3-Clause "New" or "Revised" License | 5 votes |
def test_nondecreasing_edges(self): # check for nondecreasing number of edges (for fixed number of # nodes) for n, group in groupby(self.GAG, key=nx.number_of_nodes): for m1, m2 in pairwise(map(nx.number_of_edges, group)): assert_less_equal(m2, m1 + 1)
Example #12
Source File: test_imports.py From safepy with GNU General Public License v3.0 | 5 votes |
def test_size(self): num_nodes = nx.number_of_nodes(self.graph) self.assertEqual(num_nodes, 3971, "Should be 3971.") num_edges = nx.number_of_edges(self.graph) self.assertEqual(num_edges, 28202, "Should be 28202.")
Example #13
Source File: test_function.py From Carnets with BSD 3-Clause "New" or "Revised" License | 5 votes |
def test_number_of_edges(self): assert_equal(self.G.number_of_edges(), nx.number_of_edges(self.G)) assert_equal(self.DG.number_of_edges(), nx.number_of_edges(self.DG))
Example #14
Source File: historical_tests.py From Carnets with BSD 3-Clause "New" or "Revised" License | 5 votes |
def test_order_size(self): G = self.G() G.add_edges_from([('A', 'B'), ('A', 'C'), ('B', 'D'), ('C', 'B'), ('C', 'D')]) assert_equal(G.order(), 4) assert_equal(G.size(), 5) assert_equal(G.number_of_edges(), 5) assert_equal(G.number_of_edges('A', 'B'), 1) assert_equal(G.number_of_edges('A', 'D'), 0)
Example #15
Source File: test_entangled_states.py From forest-benchmarking with Apache License 2.0 | 5 votes |
def test_create_graph_state(): graph = nx.complete_graph(4) graph = nx.relabel_nodes(graph, {i: i * 2 for i in range(4)}) prog = create_graph_state(graph) n_czs = 0 for line in prog.out().splitlines(): if line.startswith('CZ'): n_czs += 1 assert n_czs == nx.number_of_edges(graph)
Example #16
Source File: test_function.py From qgisSpaceSyntaxToolkit with GNU General Public License v3.0 | 5 votes |
def test_number_of_edges(self): assert_equal(self.G.number_of_edges(),nx.number_of_edges(self.G)) assert_equal(self.DG.number_of_edges(),nx.number_of_edges(self.DG))
Example #17
Source File: historical_tests.py From qgisSpaceSyntaxToolkit with GNU General Public License v3.0 | 5 votes |
def test_order_size(self): G=self.G() G.add_edges_from([('A', 'B'), ('A', 'C'), ('B', 'D'), ('C', 'B'), ('C', 'D')]) assert_equal(G.order(),4) assert_equal(G.size(),5) assert_equal(G.number_of_edges(),5) assert_equal(G.number_of_edges('A','B'),1) assert_equal(G.number_of_edges('A','D'),0)
Example #18
Source File: LAIS2_nx.py From cdlib with BSD 2-Clause "Simplified" License | 5 votes |
def __weight(community): """ :param community: a subgraph/algorithms in the graph :return: weight of the algorithms (using the formula mentioned in the paper) """ if nx.number_of_nodes(community) == 0: return 0 else: return float(2 * nx.number_of_edges(community) / nx.number_of_nodes(community))
Example #19
Source File: test_all.py From Carnets with BSD 3-Clause "New" or "Revised" License | 4 votes |
def test_union_all_and_compose_all(): K3 = nx.complete_graph(3) P3 = nx.path_graph(3) G1 = nx.DiGraph() G1.add_edge('A', 'B') G1.add_edge('A', 'C') G1.add_edge('A', 'D') G2 = nx.DiGraph() G2.add_edge('1', '2') G2.add_edge('1', '3') G2.add_edge('1', '4') G = nx.union_all([G1, G2]) H = nx.compose_all([G1, G2]) assert_edges_equal(G.edges(), H.edges()) assert_false(G.has_edge('A', '1')) assert_raises(nx.NetworkXError, nx.union, K3, P3) H1 = nx.union_all([H, G1], rename=('H', 'G1')) assert_equal(sorted(H1.nodes()), ['G1A', 'G1B', 'G1C', 'G1D', 'H1', 'H2', 'H3', 'H4', 'HA', 'HB', 'HC', 'HD']) H2 = nx.union_all([H, G2], rename=("H", "")) assert_equal(sorted(H2.nodes()), ['1', '2', '3', '4', 'H1', 'H2', 'H3', 'H4', 'HA', 'HB', 'HC', 'HD']) assert_false(H1.has_edge('NB', 'NA')) G = nx.compose_all([G, G]) assert_edges_equal(G.edges(), H.edges()) G2 = nx.union_all([G2, G2], rename=('', 'copy')) assert_equal(sorted(G2.nodes()), ['1', '2', '3', '4', 'copy1', 'copy2', 'copy3', 'copy4']) assert_equal(sorted(G2.neighbors('copy4')), []) assert_equal(sorted(G2.neighbors('copy1')), ['copy2', 'copy3', 'copy4']) assert_equal(len(G), 8) assert_equal(nx.number_of_edges(G), 6) E = nx.disjoint_union_all([G, G]) assert_equal(len(E), 16) assert_equal(nx.number_of_edges(E), 12) E = nx.disjoint_union_all([G1, G2]) assert_equal(sorted(E.nodes()), [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]) G1 = nx.DiGraph() G1.add_edge('A', 'B') G2 = nx.DiGraph() G2.add_edge(1, 2) G3 = nx.DiGraph() G3.add_edge(11, 22) G4 = nx.union_all([G1, G2, G3], rename=("G1", "G2", "G3")) assert_equal(sorted(G4.nodes()), ['G1A', 'G1B', 'G21', 'G22', 'G311', 'G322'])
Example #20
Source File: basic.py From Carnets with BSD 3-Clause "New" or "Revised" License | 4 votes |
def density(B, nodes): """Returns density of bipartite graph B. Parameters ---------- G : NetworkX graph nodes: list or container Nodes in one node set of the bipartite graph. Returns ------- d : float The bipartite density Examples -------- >>> from networkx.algorithms import bipartite >>> G = nx.complete_bipartite_graph(3,2) >>> X=set([0,1,2]) >>> bipartite.density(G,X) 1.0 >>> Y=set([3,4]) >>> bipartite.density(G,Y) 1.0 Notes ----- The container of nodes passed as argument must contain all nodes in one of the two bipartite node sets to avoid ambiguity in the case of disconnected graphs. See :mod:`bipartite documentation <networkx.algorithms.bipartite>` for further details on how bipartite graphs are handled in NetworkX. See Also -------- color """ n = len(B) m = nx.number_of_edges(B) nb = len(nodes) nt = n - nb if m == 0: # includes cases n==0 and n==1 d = 0.0 else: if B.is_directed(): d = m / (2.0 * float(nb * nt)) else: d = m / float(nb * nt) return d
Example #21
Source File: vectorSpatialAnalysis.py From python-urbanPlanning with MIT License | 4 votes |
def networkAnalysis_A(dataFrame): # print(pd.concat((ChicagoParkBoundaries_Pd.centroid.x, ChicagoParkBoundaries_Pd.centroid.y),axis=1)) coordi=pd.concat((dataFrame.centroid.x, dataFrame.centroid.y),axis=1) #提取patch中心点坐标,并合并 #build weights #1.distance gravity weights minDistance=pysal.lib.weights.min_threshold_distance(coordi.to_numpy()) #使用pysal库计算最小距离 # print(minDistance) weights=pysal.lib.weights.DistanceBand(coordi,threshold=minDistance*3,binary=False,alpha=-2.) #使用pysal库计算距离权重 # print(list(weights)) # print(dataFrame.columns) G=nx.Graph() #建立网络图 G.position={} #存储点位置 G.perimeter={} #存储patch周长 G.FRAC={} #存储patch的FRAC景观指数 Fractal Dimension Index G.shapeIdx={} #存储patch的形状指数 G.shape_area={} #存储patch的面积 i=0 #用于计数循环一个点到多个点,构建的边edge for (index_label, row_series) in dataFrame.iterrows(): #循环dataFrame数据,逐行读取与存储到网络图graph中 # print(index_label,"______\n",row_series["perimeter"]) # print("_"*50) #add nodes node_parkLabel=row_series["label"] #以“label”字段作为点的ID标识 G.add_node(node_parkLabel) #根据计算需要,加入属性值 G.position[node_parkLabel]=(row_series["centroid"].x,row_series["centroid"].y) G.perimeter[node_parkLabel]=row_series["shapelyLength"] G.FRAC[node_parkLabel]=row_series["FRAC"] G.shapeIdx[node_parkLabel]=row_series["shapeIdx"] G.shape_area[node_parkLabel]=row_series["shape_area"] #add edges with weights # print(weights[i]) #循环加入边 for w in weights[i]: # print(node_parkLabel) # print(w) # print(ChicagoParkBoundaries_Pd) # print(ChicagoParkBoundaries_Pd.iloc[w]["label"]) # print(weights[i][w]) G.add_edge(node_parkLabel, dataFrame.iloc[w]["label"], weight=weights[i][w]) # print(w) i+=1 print("_"*50) print("Loaded vector containing network info.") print("digraph has %d nodes with %d edges"% (nx.number_of_nodes(G), nx.number_of_edges(G))) print("_"*50) return G #基于networkx库的网络分析 network analysis_B。 参考案例:Giant Component https://networkx.github.io/documentation/stable/auto_examples/drawing/plot_giant_component.html#sphx-glr-auto-examples-drawing-plot-giant-component-py
Example #22
Source File: vectorSpatialAnalysis.py From python-urbanPlanning with MIT License | 4 votes |
def G_display(G): # make new graph H = nx.Graph() for v in G: # print(v) H.add_node(v) weightValue=list(nx.get_edge_attributes(G,'weight').values()) #提取权重 # weightsForWidth=[G[u][v]['weight'] for u,v in G.edges()] #another way # print(weightValue) import pysal.viz.mapclassify as mc q=mc.Quantiles(weightValue,k=30).bins #计算分位数,用于显示值的提取 # print(q) for (u, v, d) in tqdm(G.edges(data=True)): # print(u,v,d) # print() # print(d['weight']) if d['weight'] > q[28]: H.add_edge(u, v) print("H_digraph has %d nodes with %d edges"% (nx.number_of_nodes(H), nx.number_of_edges(H))) # draw with matplotlib/pylab plt.figure(figsize=(18, 18)) # m=2 # fig = figure(figsize=(9*m,9*m) # with nodes colored by degree sized by value elected node_color = [float(H.degree(v)) for v in H] # print(node_color) # nx.draw(H, G.position,node_size=[G.perimeter[v] for v in H],node_color=node_color, with_labels=True) weightsForWidthScale=np.interp(weightValue, (min(weightValue), max(weightValue)), (1, 3000)) #setting the edge width scaleNode=1 # sklearn.preprocessing.minmax_scale(X, feature_range=(0, 1), axis=0, copy=True) nx.draw(H, G.position,node_size=minmax_scale([G.shape_area[v]*scaleNode for v in H],feature_range=(10, 2200)), node_color=node_color,with_labels=True,edge_cmap=plt.cm.Blues,width=weightsForWidthScale) #edge_cmap=plt.cm.Blues # scale the axes equally # plt.xlim(-5000, 500) # plt.ylim(-2000, 3500) plt.show() #CSV文件转.shp格式,并返回关键信息。使用geopandas库实现
Example #23
Source File: test_all.py From qgisSpaceSyntaxToolkit with GNU General Public License v3.0 | 4 votes |
def test_union_all_and_compose_all(): K3=nx.complete_graph(3) P3=nx.path_graph(3) G1=nx.DiGraph() G1.add_edge('A','B') G1.add_edge('A','C') G1.add_edge('A','D') G2=nx.DiGraph() G2.add_edge('1','2') G2.add_edge('1','3') G2.add_edge('1','4') G=nx.union_all([G1,G2]) H=nx.compose_all([G1,G2]) assert_edges_equal(G.edges(),H.edges()) assert_false(G.has_edge('A','1')) assert_raises(nx.NetworkXError, nx.union, K3, P3) H1=nx.union_all([H,G1],rename=('H','G1')) assert_equal(sorted(H1.nodes()), ['G1A', 'G1B', 'G1C', 'G1D', 'H1', 'H2', 'H3', 'H4', 'HA', 'HB', 'HC', 'HD']) H2=nx.union_all([H,G2],rename=("H","")) assert_equal(sorted(H2.nodes()), ['1', '2', '3', '4', 'H1', 'H2', 'H3', 'H4', 'HA', 'HB', 'HC', 'HD']) assert_false(H1.has_edge('NB','NA')) G=nx.compose_all([G,G]) assert_edges_equal(G.edges(),H.edges()) G2=nx.union_all([G2,G2],rename=('','copy')) assert_equal(sorted(G2.nodes()), ['1', '2', '3', '4', 'copy1', 'copy2', 'copy3', 'copy4']) assert_equal(G2.neighbors('copy4'),[]) assert_equal(sorted(G2.neighbors('copy1')),['copy2', 'copy3', 'copy4']) assert_equal(len(G),8) assert_equal(nx.number_of_edges(G),6) E=nx.disjoint_union_all([G,G]) assert_equal(len(E),16) assert_equal(nx.number_of_edges(E),12) E=nx.disjoint_union_all([G1,G2]) assert_equal(sorted(E.nodes()),[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]) G1=nx.DiGraph() G1.add_edge('A','B') G2=nx.DiGraph() G2.add_edge(1,2) G3=nx.DiGraph() G3.add_edge(11,22) G4=nx.union_all([G1,G2,G3],rename=("G1","G2","G3")) assert_equal(sorted(G4.nodes()), ['G1A', 'G1B', 'G21', 'G22', 'G311', 'G322'])
Example #24
Source File: basic.py From qgisSpaceSyntaxToolkit with GNU General Public License v3.0 | 4 votes |
def density(B, nodes): """Return density of bipartite graph B. Parameters ---------- G : NetworkX graph nodes: list or container Nodes in one set of the bipartite graph. Returns ------- d : float The bipartite density Examples -------- >>> from networkx.algorithms import bipartite >>> G = nx.complete_bipartite_graph(3,2) >>> X=set([0,1,2]) >>> bipartite.density(G,X) 1.0 >>> Y=set([3,4]) >>> bipartite.density(G,Y) 1.0 See Also -------- color """ n=len(B) m=nx.number_of_edges(B) nb=len(nodes) nt=n-nb if m==0: # includes cases n==0 and n==1 d=0.0 else: if B.is_directed(): d=m/(2.0*float(nb*nt)) else: d= m/float(nb*nt) return d
Example #25
Source File: basic.py From aws-kube-codesuite with Apache License 2.0 | 4 votes |
def density(B, nodes): """Return density of bipartite graph B. Parameters ---------- G : NetworkX graph nodes: list or container Nodes in one node set of the bipartite graph. Returns ------- d : float The bipartite density Examples -------- >>> from networkx.algorithms import bipartite >>> G = nx.complete_bipartite_graph(3,2) >>> X=set([0,1,2]) >>> bipartite.density(G,X) 1.0 >>> Y=set([3,4]) >>> bipartite.density(G,Y) 1.0 Notes ----- The container of nodes passed as argument must contain all nodes in one of the two bipartite node sets to avoid ambiguity in the case of disconnected graphs. See :mod:`bipartite documentation <networkx.algorithms.bipartite>` for further details on how bipartite graphs are handled in NetworkX. See Also -------- color """ n=len(B) m=nx.number_of_edges(B) nb=len(nodes) nt=n-nb if m==0: # includes cases n==0 and n==1 d=0.0 else: if B.is_directed(): d=m/(2.0*float(nb*nt)) else: d= m/float(nb*nt) return d
Example #26
Source File: test_all.py From aws-kube-codesuite with Apache License 2.0 | 4 votes |
def test_union_all_and_compose_all(): K3=nx.complete_graph(3) P3=nx.path_graph(3) G1=nx.DiGraph() G1.add_edge('A','B') G1.add_edge('A','C') G1.add_edge('A','D') G2=nx.DiGraph() G2.add_edge('1','2') G2.add_edge('1','3') G2.add_edge('1','4') G=nx.union_all([G1,G2]) H=nx.compose_all([G1,G2]) assert_edges_equal(G.edges(),H.edges()) assert_false(G.has_edge('A','1')) assert_raises(nx.NetworkXError, nx.union, K3, P3) H1=nx.union_all([H,G1],rename=('H','G1')) assert_equal(sorted(H1.nodes()), ['G1A', 'G1B', 'G1C', 'G1D', 'H1', 'H2', 'H3', 'H4', 'HA', 'HB', 'HC', 'HD']) H2=nx.union_all([H,G2],rename=("H","")) assert_equal(sorted(H2.nodes()), ['1', '2', '3', '4', 'H1', 'H2', 'H3', 'H4', 'HA', 'HB', 'HC', 'HD']) assert_false(H1.has_edge('NB','NA')) G=nx.compose_all([G,G]) assert_edges_equal(G.edges(),H.edges()) G2=nx.union_all([G2,G2],rename=('','copy')) assert_equal(sorted(G2.nodes()), ['1', '2', '3', '4', 'copy1', 'copy2', 'copy3', 'copy4']) assert_equal(sorted(G2.neighbors('copy4')),[]) assert_equal(sorted(G2.neighbors('copy1')),['copy2', 'copy3', 'copy4']) assert_equal(len(G),8) assert_equal(nx.number_of_edges(G),6) E=nx.disjoint_union_all([G,G]) assert_equal(len(E),16) assert_equal(nx.number_of_edges(E),12) E=nx.disjoint_union_all([G1,G2]) assert_equal(sorted(E.nodes()),[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]) G1=nx.DiGraph() G1.add_edge('A','B') G2=nx.DiGraph() G2.add_edge(1,2) G3=nx.DiGraph() G3.add_edge(11,22) G4=nx.union_all([G1,G2,G3],rename=("G1","G2","G3")) assert_equal(sorted(G4.nodes()), ['G1A', 'G1B', 'G21', 'G22', 'G311', 'G322'])