本文整理汇总了Python中networkx.read_adjlist方法的典型用法代码示例。如果您正苦于以下问题:Python networkx.read_adjlist方法的具体用法?Python networkx.read_adjlist怎么用?Python networkx.read_adjlist使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类networkx
的用法示例。
在下文中一共展示了networkx.read_adjlist方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: read_adjlist
# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import read_adjlist [as 别名]
def read_adjlist(self, filename):
""" Read graph from adjacency file in which the edge must be unweighted
the format of each line: v1 n1 n2 n3 ... nk
:param filename: the filename of input file
"""
self.G = nx.read_adjlist(filename, create_using=nx.DiGraph())
for i, j in self.G.edges():
self.G[i][j]['weight'] = 1.0
self.encode_node()
示例2: read_adjlist
# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import read_adjlist [as 别名]
def read_adjlist(self, filename):
""" Read graph from adjacency file in which the edge must be unweighted
the format of each line: v1 n1 n2 n3 ... nk
:param filename: the filename of input file
"""
self.G = nx.read_adjlist(filename, nodetype=int, create_using=nx.DiGraph())
for i, j in self.G.edges():
self.G[i][j]['weight'] = 1.0
self.encode_node()
示例3: test_adjlist_graph
# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import read_adjlist [as 别名]
def test_adjlist_graph(self):
G=self.G
(fd,fname)=tempfile.mkstemp()
nx.write_adjlist(G,fname)
H=nx.read_adjlist(fname)
H2=nx.read_adjlist(fname)
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)
示例4: test_adjlist_digraph
# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import read_adjlist [as 别名]
def test_adjlist_digraph(self):
G=self.DG
(fd,fname)=tempfile.mkstemp()
nx.write_adjlist(G,fname)
H=nx.read_adjlist(fname,create_using=nx.DiGraph())
H2=nx.read_adjlist(fname,create_using=nx.DiGraph())
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)
示例5: test_adjlist_integers
# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import read_adjlist [as 别名]
def test_adjlist_integers(self):
(fd,fname)=tempfile.mkstemp()
G=nx.convert_node_labels_to_integers(self.G)
nx.write_adjlist(G,fname)
H=nx.read_adjlist(fname,nodetype=int)
H2=nx.read_adjlist(fname,nodetype=int)
assert_nodes_equal(H.nodes(),G.nodes())
assert_edges_equal(H.edges(),G.edges())
os.close(fd)
os.unlink(fname)
示例6: test_adjlist_multigraph
# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import read_adjlist [as 别名]
def test_adjlist_multigraph(self):
G=self.XG
(fd,fname)=tempfile.mkstemp()
nx.write_adjlist(G,fname)
H=nx.read_adjlist(fname,nodetype=int,
create_using=nx.MultiGraph())
H2=nx.read_adjlist(fname,nodetype=int,
create_using=nx.MultiGraph())
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)
示例7: test_adjlist_multidigraph
# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import read_adjlist [as 别名]
def test_adjlist_multidigraph(self):
G=self.XDG
(fd,fname)=tempfile.mkstemp()
nx.write_adjlist(G,fname)
H=nx.read_adjlist(fname,nodetype=int,
create_using=nx.MultiDiGraph())
H2=nx.read_adjlist(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)
示例8: test_adjlist_delimiter
# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import read_adjlist [as 别名]
def test_adjlist_delimiter(self):
fh=io.BytesIO()
G = nx.path_graph(3)
nx.write_adjlist(G, fh, delimiter=':')
fh.seek(0)
H = nx.read_adjlist(fh, nodetype=int, delimiter=':')
assert_nodes_equal(H.nodes(),G.nodes())
assert_edges_equal(H.edges(),G.edges())
示例9: test_adjlist_graph
# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import read_adjlist [as 别名]
def test_adjlist_graph(self):
G = self.G
(fd, fname) = tempfile.mkstemp()
nx.write_adjlist(G, fname)
H = nx.read_adjlist(fname)
H2 = nx.read_adjlist(fname)
assert_not_equal(H, H2) # they should be different graphs
assert_nodes_equal(list(H), list(G))
assert_edges_equal(list(H.edges()), list(G.edges()))
os.close(fd)
os.unlink(fname)
示例10: test_adjlist_digraph
# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import read_adjlist [as 别名]
def test_adjlist_digraph(self):
G = self.DG
(fd, fname) = tempfile.mkstemp()
nx.write_adjlist(G, fname)
H = nx.read_adjlist(fname, create_using=nx.DiGraph())
H2 = nx.read_adjlist(fname, create_using=nx.DiGraph())
assert_not_equal(H, H2) # they should be different graphs
assert_nodes_equal(list(H), list(G))
assert_edges_equal(list(H.edges()), list(G.edges()))
os.close(fd)
os.unlink(fname)
示例11: test_adjlist_integers
# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import read_adjlist [as 别名]
def test_adjlist_integers(self):
(fd, fname) = tempfile.mkstemp()
G = nx.convert_node_labels_to_integers(self.G)
nx.write_adjlist(G, fname)
H = nx.read_adjlist(fname, nodetype=int)
H2 = nx.read_adjlist(fname, nodetype=int)
assert_nodes_equal(list(H), list(G))
assert_edges_equal(list(H.edges()), list(G.edges()))
os.close(fd)
os.unlink(fname)
示例12: test_adjlist_multidigraph
# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import read_adjlist [as 别名]
def test_adjlist_multidigraph(self):
G = self.XDG
(fd, fname) = tempfile.mkstemp()
nx.write_adjlist(G, fname)
H = nx.read_adjlist(fname, nodetype=int,
create_using=nx.MultiDiGraph())
H2 = nx.read_adjlist(fname, nodetype=int,
create_using=nx.MultiDiGraph())
assert_not_equal(H, H2) # they should be different graphs
assert_nodes_equal(list(H), list(G))
assert_edges_equal(list(H.edges()), list(G.edges()))
os.close(fd)
os.unlink(fname)
示例13: test_adjlist_delimiter
# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import read_adjlist [as 别名]
def test_adjlist_delimiter(self):
fh = io.BytesIO()
G = nx.path_graph(3)
nx.write_adjlist(G, fh, delimiter=':')
fh.seek(0)
H = nx.read_adjlist(fh, nodetype=int, delimiter=':')
assert_nodes_equal(list(H), list(G))
assert_edges_equal(list(H.edges()), list(G.edges()))
示例14: test_adjlist_graph
# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import read_adjlist [as 别名]
def test_adjlist_graph(self):
G=self.G
(fd,fname)=tempfile.mkstemp()
nx.write_adjlist(G,fname)
H=nx.read_adjlist(fname)
H2=nx.read_adjlist(fname)
assert_not_equal(H,H2) # they should be different graphs
assert_nodes_equal(list(H), list(G))
assert_edges_equal(list(H.edges()), list(G.edges()))
os.close(fd)
os.unlink(fname)
示例15: test_adjlist_digraph
# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import read_adjlist [as 别名]
def test_adjlist_digraph(self):
G=self.DG
(fd,fname)=tempfile.mkstemp()
nx.write_adjlist(G,fname)
H=nx.read_adjlist(fname,create_using=nx.DiGraph())
H2=nx.read_adjlist(fname,create_using=nx.DiGraph())
assert_not_equal(H,H2) # they should be different graphs
assert_nodes_equal(list(H), list(G))
assert_edges_equal(list(H.edges()), list(G.edges()))
os.close(fd)
os.unlink(fname)