本文整理汇总了Python中networkx.write_edgelist方法的典型用法代码示例。如果您正苦于以下问题:Python networkx.write_edgelist方法的具体用法?Python networkx.write_edgelist怎么用?Python networkx.write_edgelist使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类networkx
的用法示例。
在下文中一共展示了networkx.write_edgelist方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_demon_lib
# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import write_edgelist [as 别名]
def test_demon_lib(self):
g = nx.karate_club_graph()
nx.write_edgelist(g, "test.csv", delimiter=" ")
D = d.Demon(network_filename="test.csv", epsilon=0.3)
coms = D.execute()
print(coms)
self.assertEqual(len(coms), 2)
D = d.Demon(graph=g, file_output="communities.txt", epsilon=0.3)
D.execute()
f = open("communities.txt")
count = 0
for _ in f:
count += 1
self.assertEqual(count, 2)
os.remove("test.csv")
os.remove("communities.txt")
示例2: setup_class
# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import write_edgelist [as 别名]
def setup_class(self, tmpdir):
n = 10
p = 0.5
wt = np.random.exponential
wtargs = dict(scale=4)
np.random.seed(1)
self.A = gs.simulations.er_np(n, p)
self.B = gs.simulations.er_np(n, p, wt=wt, wtargs=wtargs)
G_A = nx.from_numpy_array(self.A)
G_B = nx.from_numpy_array(self.B)
G_B = nx.relabel_nodes(G_B, lambda x: x + 10) # relabel nodes to go from 10-19.
self.A_path = str(tmpdir / "A_unweighted.edgelist")
self.B_path = str(tmpdir / "B.edgelist")
self.root = str(tmpdir)
nx.write_edgelist(G_A, self.A_path, data=False)
nx.write_weighted_edgelist(G_B, self.B_path)
示例3: test_latin1
# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import write_edgelist [as 别名]
def test_latin1(self):
G = nx.Graph()
try: # Python 3.x
blurb = chr(1245) # just to trigger the exception
name1 = 'Bj' + chr(246) + 'rk'
name2 = chr(220) + 'ber'
except ValueError: # Python 2.6+
name1 = 'Bj' + unichr(246) + 'rk'
name2 = unichr(220) + 'ber'
G.add_edge(name1, 'Radiohead', attr_dict={name2: 3})
fd, fname = tempfile.mkstemp()
nx.write_edgelist(G, fname, encoding = 'latin-1')
H = nx.read_edgelist(fname, encoding = 'latin-1')
assert_graphs_equal(G, H)
os.close(fd)
os.unlink(fname)
示例4: test_latin1
# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import write_edgelist [as 别名]
def test_latin1(self):
G = nx.Graph()
try: # Python 3.x
blurb = chr(1245) # just to trigger the exception
name1 = 'Bj' + chr(246) + 'rk'
name2 = chr(220) + 'ber'
except ValueError: # Python 2.6+
name1 = 'Bj' + unichr(246) + 'rk'
name2 = unichr(220) + 'ber'
G.add_edge(name1, 'Radiohead', **{name2: 3})
fd, fname = tempfile.mkstemp()
nx.write_edgelist(G, fname, encoding='latin-1')
H = nx.read_edgelist(fname, encoding='latin-1')
assert_graphs_equal(G, H)
os.close(fd)
os.unlink(fname)
示例5: test_latin1
# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import write_edgelist [as 别名]
def test_latin1(self):
G = nx.Graph()
try: # Python 3.x
blurb = chr(1245) # just to trigger the exception
name1 = 'Bj' + chr(246) + 'rk'
name2 = chr(220) + 'ber'
except ValueError: # Python 2.6+
name1 = 'Bj' + unichr(246) + 'rk'
name2 = unichr(220) + 'ber'
G.add_edge(name1, 'Radiohead', **{name2: 3})
fd, fname = tempfile.mkstemp()
nx.write_edgelist(G, fname, encoding = 'latin-1')
H = nx.read_edgelist(fname, encoding = 'latin-1')
assert_graphs_equal(G, H)
os.close(fd)
os.unlink(fname)
示例6: dump_info
# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import write_edgelist [as 别名]
def dump_info(self, tmpdir):
"""Dump info to test directory"""
pred_graph_fn = os.path.join(tmpdir, 'final_predicted_network_graph.txt')
networkx.write_edgelist(self.predicted_network_graph, pred_graph_fn)
act_graph_fn = os.path.join(tmpdir, 'final_actual_network_graph.txt')
networkx.write_edgelist(self.host_connectivity_graph, act_graph_fn)
fault_list_fn = os.path.join(tmpdir, 'fault_list.txt')
file = open(fault_list_fn, 'w')
for fault_name in self.fault_list:
file.write(fault_name + '\n')
示例7: test_write_edgelist_1
# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import write_edgelist [as 别名]
def test_write_edgelist_1(self):
fh=io.BytesIO()
G=nx.Graph()
G.add_edges_from([(1,2),(2,3)])
nx.write_edgelist(G,fh,data=False)
fh.seek(0)
assert_equal(fh.read(),b"1 2\n2 3\n")
示例8: test_write_edgelist_2
# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import write_edgelist [as 别名]
def test_write_edgelist_2(self):
fh=io.BytesIO()
G=nx.Graph()
G.add_edges_from([(1,2),(2,3)])
nx.write_edgelist(G,fh,data=True)
fh.seek(0)
assert_equal(fh.read(),b"1 2 {}\n2 3 {}\n")
示例9: test_write_edgelist_3
# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import write_edgelist [as 别名]
def test_write_edgelist_3(self):
fh=io.BytesIO()
G=nx.Graph()
G.add_edge(1,2,weight=2.0)
G.add_edge(2,3,weight=3.0)
nx.write_edgelist(G,fh,data=True)
fh.seek(0)
assert_equal(fh.read(),b"1 2 {'weight': 2.0}\n2 3 {'weight': 3.0}\n")
示例10: test_write_edgelist_4
# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import write_edgelist [as 别名]
def test_write_edgelist_4(self):
fh=io.BytesIO()
G=nx.Graph()
G.add_edge(1,2,weight=2.0)
G.add_edge(2,3,weight=3.0)
nx.write_edgelist(G,fh,data=[('weight')])
fh.seek(0)
assert_equal(fh.read(),b"1 2 2.0\n2 3 3.0\n")
示例11: test_unicode
# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import write_edgelist [as 别名]
def test_unicode(self):
G = nx.Graph()
try: # Python 3.x
name1 = chr(2344) + chr(123) + chr(6543)
name2 = chr(5543) + chr(1543) + chr(324)
except ValueError: # Python 2.6+
name1 = unichr(2344) + unichr(123) + unichr(6543)
name2 = unichr(5543) + unichr(1543) + unichr(324)
G.add_edge(name1, 'Radiohead', attr_dict={name2: 3})
fd, fname = tempfile.mkstemp()
nx.write_edgelist(G, fname)
H = nx.read_edgelist(fname)
assert_graphs_equal(G, H)
os.close(fd)
os.unlink(fname)
示例12: test_edgelist_graph
# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import write_edgelist [as 别名]
def test_edgelist_graph(self):
G=self.G
(fd,fname)=tempfile.mkstemp()
nx.write_edgelist(G,fname)
H=nx.read_edgelist(fname)
H2=nx.read_edgelist(fname)
assert_not_equal(H,H2) # they should be different graphs
G.remove_node('g') # isolated nodes are not written in edgelist
assert_nodes_equal(H.nodes(),G.nodes())
assert_edges_equal(H.edges(),G.edges())
os.close(fd)
os.unlink(fname)
示例13: test_edgelist_digraph
# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import write_edgelist [as 别名]
def test_edgelist_digraph(self):
G=self.DG
(fd,fname)=tempfile.mkstemp()
nx.write_edgelist(G,fname)
H=nx.read_edgelist(fname,create_using=nx.DiGraph())
H2=nx.read_edgelist(fname,create_using=nx.DiGraph())
assert_not_equal(H,H2) # they should be different graphs
G.remove_node('g') # isolated nodes are not written in edgelist
assert_nodes_equal(H.nodes(),G.nodes())
assert_edges_equal(H.edges(),G.edges())
os.close(fd)
os.unlink(fname)
示例14: test_edgelist_integers
# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import write_edgelist [as 别名]
def test_edgelist_integers(self):
G=nx.convert_node_labels_to_integers(self.G)
(fd,fname)=tempfile.mkstemp()
nx.write_edgelist(G,fname)
H=nx.read_edgelist(fname,nodetype=int)
# isolated nodes are not written in edgelist
G.remove_nodes_from(nx.isolates(G))
assert_nodes_equal(H.nodes(),G.nodes())
assert_edges_equal(H.edges(),G.edges())
os.close(fd)
os.unlink(fname)
示例15: test_edgelist_multidigraph
# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import write_edgelist [as 别名]
def test_edgelist_multidigraph(self):
G=self.XDG
(fd,fname)=tempfile.mkstemp()
nx.write_edgelist(G,fname)
H=nx.read_edgelist(fname,nodetype=int,create_using=nx.MultiDiGraph())
H2=nx.read_edgelist(fname,nodetype=int,create_using=nx.MultiDiGraph())
assert_not_equal(H,H2) # they should be different graphs
assert_nodes_equal(H.nodes(),G.nodes())
assert_edges_equal(H.edges(),G.edges())
os.close(fd)
os.unlink(fname)