Graph.get_edge_data#
- Graph.get_edge_data(u, v, default=None)[源码]#
返回与边 (u, v) 关联的属性字典。
这与
G[u][v]
相同,但如果边不存在,则返回 default 值而不是引发异常。- 参数:
- u, v节点
- default: 任意 Python 对象(默认值=None)
如果未找到边 (u, v),则返回的值。
- 返回:
- edge_dict字典
边的属性字典。
示例
>>> G = nx.path_graph(4) # or DiGraph, MultiGraph, MultiDiGraph, etc >>> G[0][1] {}
警告:不允许对
G[u][v]
进行赋值。但对属性G[u][v]['foo']
赋值是安全的。>>> G[0][1]["weight"] = 7 >>> G[0][1]["weight"] 7 >>> G[1][0]["weight"] 7
>>> G = nx.path_graph(4) # or DiGraph, MultiGraph, MultiDiGraph, etc >>> G.get_edge_data(0, 1) # default edge data is {} {} >>> e = (0, 1) >>> G.get_edge_data(*e) # tuple form {} >>> G.get_edge_data("a", "b", default=0) # edge not in graph, return 0 0