get_edge_attributes#
- get_edge_attributes(G, name, default=None)[source]#
从图中获取边属性
- 参数:
- GNetworkX 图
- name字符串
属性名称
- default: 对象 (默认为 None)
如果图中没有为该边设置属性值,则为其默认值。如果为
None
,则返回的字典中不包含没有此属性的边。
- 返回:
- 以边为键的属性字典。对于(有向)图,键是
- 形式为 (u, v) 的 2 元组。对于多重(有向)图,键是
- 形式为 (u, v, key) 的 3 元组。
示例
>>> G = nx.Graph() >>> nx.add_path(G, [1, 2, 3], color="red") >>> color = nx.get_edge_attributes(G, "color") >>> color[(1, 2)] 'red' >>> G.add_edge(3, 4) >>> color = nx.get_edge_attributes(G, "color", default="yellow") >>> color[(3, 4)] 'yellow'