parse_edgelist#
- parse_edgelist(lines, comments='#', delimiter=None, create_using=None, nodetype=None, data=True)[源码]#
解析图的边列表表示的行。
- 参数:
- 返回:
- G: NetworkX 图
与行对应的图
示例
没有数据的边列表
>>> 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 dictionary representation 数据的边列表
>>> 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})]
包含列表数据的边列表
>>> 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})]