当前位置: 首页>>代码示例>>Python>>正文


Python networkx.read_multiline_adjlist函数代码示例

本文整理汇总了Python中networkx.read_multiline_adjlist函数的典型用法代码示例。如果您正苦于以下问题:Python read_multiline_adjlist函数的具体用法?Python read_multiline_adjlist怎么用?Python read_multiline_adjlist使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了read_multiline_adjlist函数的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_multiline_adjlist_integers

 def test_multiline_adjlist_integers(self):
     (fd, fname) = tempfile.mkstemp()
     G = nx.convert_node_labels_to_integers(self.G)
     nx.write_multiline_adjlist(G, fname)
     H = nx.read_multiline_adjlist(fname, nodetype=int)
     H2 = nx.read_multiline_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:yamaguchiyuto,项目名称:networkx,代码行数:10,代码来源:test_adjlist.py

示例2: test_multiline_adjlist_digraph

 def test_multiline_adjlist_digraph(self):
     G = self.DG
     (fd, fname) = tempfile.mkstemp()
     nx.write_multiline_adjlist(G, fname)
     H = nx.read_multiline_adjlist(fname, create_using=nx.DiGraph())
     H2 = nx.read_multiline_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:yamaguchiyuto,项目名称:networkx,代码行数:11,代码来源:test_adjlist.py

示例3: test_multiline_adjlist_graph

 def test_multiline_adjlist_graph(self):
     G=self.G
     (fd,fname)=tempfile.mkstemp()
     nx.write_multiline_adjlist(G,fname)  
     H=nx.read_multiline_adjlist(fname)
     H2=nx.read_multiline_adjlist(fname)
     assert_not_equal(H,H2) # they should be different graphs
     assert_equal(sorted(H.nodes()),sorted(G.nodes()))
     assert_equal(sorted(H.edges()),sorted(G.edges()))
     os.close(fd)
     os.unlink(fname)
开发者ID:c0ns0le,项目名称:zenoss-4,代码行数:11,代码来源:test_adjlist.py

示例4: test_multiline_adjlist_delimiter

 def test_multiline_adjlist_delimiter(self):
     fh = io.BytesIO()
     G = nx.path_graph(3)
     nx.write_multiline_adjlist(G, fh, delimiter=':')
     fh.seek(0)
     H = nx.read_multiline_adjlist(fh, nodetype=int, delimiter=':')
     assert_nodes_equal(list(H), list(G))
     assert_edges_equal(list(H.edges()), list(G.edges()))
开发者ID:yamaguchiyuto,项目名称:networkx,代码行数:8,代码来源:test_adjlist.py

示例5: test_read_multiline_adjlist_1

    def test_read_multiline_adjlist_1(self):
        # Unit test for https://networkx.lanl.gov/trac/ticket/252
        s = b"""# comment line
1 2
# comment line
2
3
"""
        bytesIO = io.BytesIO(s)
        G = nx.read_multiline_adjlist(bytesIO)
        adj = {'1': {'3': {}, '2': {}}, '3': {'1': {}}, '2': {'1': {}}}
        assert_graphs_equal(G, nx.Graph(adj))
开发者ID:yamaguchiyuto,项目名称:networkx,代码行数:12,代码来源:test_adjlist.py

示例6: test_unicode

 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', **{name2: 3})
     fd, fname = tempfile.mkstemp()
     nx.write_multiline_adjlist(G, fname)
     H = nx.read_multiline_adjlist(fname)
     assert_graphs_equal(G, H)
     os.close(fd)
     os.unlink(fname)
开发者ID:yamaguchiyuto,项目名称:networkx,代码行数:15,代码来源:test_adjlist.py

示例7: test_read_multiline_adjlist_1

def test_read_multiline_adjlist_1():
    # Unit test for https://networkx.lanl.gov/trac/ticket/252
    s = """# comment line
1 2
# comment line
2
3
"""
    import StringIO
    strIO = StringIO.StringIO(s)

    G = nx.read_multiline_adjlist(strIO)
    adj = {'1': {'3': {}, '2': {}}, '3': {'1': {}}, '2': {'1': {}}}
    
    assert_equal(G.adj, adj)
开发者ID:JaneliaSciComp,项目名称:Neuroptikon,代码行数:15,代码来源:test_adjlist.py

示例8: test_latin1

 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_multiline_adjlist(G, fname, encoding='latin-1')
     H = nx.read_multiline_adjlist(fname, encoding='latin-1')
     assert_graphs_equal(G, H)
     os.close(fd)
     os.unlink(fname)
开发者ID:yamaguchiyuto,项目名称:networkx,代码行数:16,代码来源:test_adjlist.py

示例9: test_latin1

 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_multiline_adjlist(G, fname, encoding="latin-1")
     H = nx.read_multiline_adjlist(fname, encoding="latin-1")
     assert_graphs_equal(G, H)
     os.close(fd)
     os.unlink(fname)
开发者ID:nishnik,项目名称:networkx,代码行数:16,代码来源:test_adjlist.py

示例10: read_graph

def read_graph(from_user, to_user):
    try:
        with get_file(edgelist_fname(**locals()), 'r') as fd:
            return NX.read_multiline_adjlist(fd, delimiter='\t')
    except IOError:
        return None
开发者ID:kwargs,项目名称:ya-foaf,代码行数:6,代码来源:get_paths.py

示例11: open

G.add_edge(hd, mh)
G.add_edge(mc, st)
G.add_edge(boc, mc)
G.add_edge(boc, dt)
G.add_edge(st, dt)
G.add_edge(q, st)
G.add_edge(dt, mh)
G.add_edge(st, mh)

# write in UTF-8 encoding
fh = open('edgelist.utf-8', 'wb')
fh.write('# -*- coding: utf-8 -*-\n'.encode('utf-8'))  # encoding hint for emacs
nx.write_multiline_adjlist(G, fh, delimiter='\t', encoding='utf-8')

# read and store in UTF-8
fh = open('edgelist.utf-8', 'rb')
H = nx.read_multiline_adjlist(fh, delimiter='\t', encoding='utf-8')

for n in G.nodes():
    if n not in H:
        print(False)

print(list(G.nodes()))

pos = nx.spring_layout(G)
nx.draw(G, pos, font_size=16, with_labels=False)
for p in pos:  # raise text positions
    pos[p][1] += 0.07
nx.draw_networkx_labels(G, pos)
plt.show()
开发者ID:aparamon,项目名称:networkx,代码行数:30,代码来源:plot_heavy_metal_umlaut.py


注:本文中的networkx.read_multiline_adjlist函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。