本文整理匯總了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)