Networkx: Use common function for edge weight calculation
问题 Suppose I have a function euc_2d(graph, n1, n2) that calculates the euclidean distance between two nodes of the same graph. Each nodes has a given pos=(x,y) which is assigned on graph creation. NetworkX provides a function to get the total weight of all edges of a graph namely graph.size(weight='weight') . The problem with this method is that it assumes that whenever I add an edge I should explicitly assign the appropriate edge weight like graph.add_edge(u,v,weight=?) using a lambda function