parse_edgelist#
- parse_edgelist(lines, comments='#', delimiter=None, create_using=None, nodetype=None, data=True)[源代码]#
解析二部图的边列表表示的行。
- 参数
- lines字符串的列表或迭代器
以边缘列表格式输入数据
- comments字符串,可选
注释行的标记
- delimiter字符串,可选
节点标签的分隔符
- create_using: NetworkX graph container, optional
使用给定的网络X图来保存节点或边。
- nodetypePython类型,可选
将节点转换为此类型。
- data布尔或(标签、类型)元组列表
如果为False,则不生成边缘数据;如果为True,则使用边缘数据的字典表示形式,或者使用为边缘数据指定字典关键字名称和类型的列表元组。
- 返回
- G:网络X图形
对应于线的二部图
实例
没有数据的边缘列表:
>>> from networkx.algorithms import bipartite >>> lines = ["1 2", "2 3", "3 4"] >>> G = bipartite.parse_edgelist(lines, nodetype=int) >>> sorted(G.nodes()) [1, 2, 3, 4] >>> sorted(G.nodes(data=True)) [(1, {'bipartite': 0}), (2, {'bipartite': 0}), (3, {'bipartite': 0}), (4, {'bipartite': 1})] >>> sorted(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 = bipartite.parse_edgelist(lines, nodetype=int) >>> sorted(G.nodes()) [1, 2, 3, 4] >>> sorted(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 = bipartite.parse_edgelist(lines, nodetype=int, data=(("weight", float),)) >>> sorted(G.nodes()) [1, 2, 3, 4] >>> sorted(G.edges(data=True)) [(1, 2, {'weight': 3.0}), (2, 3, {'weight': 27.0}), (3, 4, {'weight': 3.0})]