當前位置: 首頁>>代碼示例>>Python>>正文


Python networkx.read_adjlist方法代碼示例

本文整理匯總了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() 
開發者ID:thunlp,項目名稱:OpenNE,代碼行數:11,代碼來源:graph.py

示例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() 
開發者ID:xchadesi,項目名稱:GPF,代碼行數:11,代碼來源:graph.py

示例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) 
開發者ID:SpaceGroupUCL,項目名稱:qgisSpaceSyntaxToolkit,代碼行數:13,代碼來源:test_adjlist.py

示例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) 
開發者ID:SpaceGroupUCL,項目名稱:qgisSpaceSyntaxToolkit,代碼行數:13,代碼來源:test_adjlist.py

示例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) 
開發者ID:SpaceGroupUCL,項目名稱:qgisSpaceSyntaxToolkit,代碼行數:12,代碼來源:test_adjlist.py

示例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) 
開發者ID:SpaceGroupUCL,項目名稱:qgisSpaceSyntaxToolkit,代碼行數:15,代碼來源:test_adjlist.py

示例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) 
開發者ID:SpaceGroupUCL,項目名稱:qgisSpaceSyntaxToolkit,代碼行數:15,代碼來源:test_adjlist.py

示例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()) 
開發者ID:SpaceGroupUCL,項目名稱:qgisSpaceSyntaxToolkit,代碼行數:10,代碼來源:test_adjlist.py

示例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) 
開發者ID:holzschu,項目名稱:Carnets,代碼行數:13,代碼來源:test_adjlist.py

示例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) 
開發者ID:holzschu,項目名稱:Carnets,代碼行數:13,代碼來源:test_adjlist.py

示例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) 
開發者ID:holzschu,項目名稱:Carnets,代碼行數:12,代碼來源:test_adjlist.py

示例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) 
開發者ID:holzschu,項目名稱:Carnets,代碼行數:15,代碼來源:test_adjlist.py

示例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())) 
開發者ID:holzschu,項目名稱:Carnets,代碼行數:10,代碼來源:test_adjlist.py

示例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) 
開發者ID:aws-samples,項目名稱:aws-kube-codesuite,代碼行數:13,代碼來源:test_adjlist.py

示例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) 
開發者ID:aws-samples,項目名稱:aws-kube-codesuite,代碼行數:13,代碼來源:test_adjlist.py


注:本文中的networkx.read_adjlist方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。