parse_edgelist#
- parse_edgelist(lines, comments='#', delimiter=None, create_using=None, nodetype=None, data=True)[源代码]#
解析图的边列表表示形式的行。
- 参数
- 返回
- G:网络X图形
与线相对应的图形
实例
没有数据的边缘列表:
>>> lines = ["1 2", "2 3", "3 4"] >>> G = nx.parse_edgelist(lines, nodetype=int) >>> list(G) [1, 2, 3, 4] >>> list(G.edges()) [(1, 2), (2, 3), (3, 4)]
用python字典表示的数据的edgelist:
>>> lines = ["1 2 {'weight': 3}", "2 3 {'weight': 27}", "3 4 {'weight': 3.0}"] >>> G = nx.parse_edgelist(lines, nodetype=int) >>> list(G) [1, 2, 3, 4] >>> list(G.edges(data=True)) [(1, 2, {'weight': 3}), (2, 3, {'weight': 27}), (3, 4, {'weight': 3.0})]
数据在列表中的EdgeList:
>>> lines = ["1 2 3", "2 3 27", "3 4 3.0"] >>> G = nx.parse_edgelist(lines, nodetype=int, data=(("weight", float),)) >>> list(G) [1, 2, 3, 4] >>> list(G.edges(data=True)) [(1, 2, {'weight': 3.0}), (2, 3, {'weight': 27.0}), (3, 4, {'weight': 3.0})]