1.查看节点、边属性
for k,v in G.nodes(data=True):
print(k,v)
elarge = [(u, v) for (u, v, d) in G.edges(data=True) if d["weight"] > 0.5]
2.判断有向图中节点是否连通:
if str(good_anchor[i][0]) in (nx.algorithms.dag.descendants(G2,str(v2c_new[i][k]))):
distance, path = nx.single_source_dijkstra(G2,source=str(v2c_new[i][k]),target=str(good_anchor[i][0]), weight='length') #good_anchor是目标点
配合nx.shortest_path用
3.查看边属性
G.add_edge(1, 2, key='xyz', weight=7)
G.get_edge_data(1, 2, key='xyz')
G.edges[8,4]
4.构建带权重图
for i in edge_list_set:
G2.add_edge(i[0],i[1],length=-i[2]+187)
G = nx.DiGraph()
G.add_weighted_edges_from(edge_list_set)
5.osmnx
https://geoffboeing.com/2016/11/osmnx-python-street-networks/