Graph.get_edge_data#
- Graph.get_edge_data(u, v, default=None)[源代码]#
返回与边(u,v)关联的属性字典。
这和
G[u][v]
除非默认不存在,否则返回默认值而不是异常。- 参数
- u, v节点
- default: any Python object (default=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