Skip to content

Instantly share code, notes, and snippets.

@plotti
Created May 24, 2012 14:39
Show Gist options
  • Save plotti/2781952 to your computer and use it in GitHub Desktop.
Save plotti/2781952 to your computer and use it in GitHub Desktop.
def total_edge_weight(D):
total = 0
for edge in D.edges(data=True):
total += edge[2]["weight"]
return total
def average_tie_strength(D):
return float(total_edge_weight(D))/len(D.edges())
D = nx.DiGraph()
D.add_nodes_from([1,2])
D.add_edges_from([(1,2)])
D[1][2]["weight"] = 3
total_edge_weight(D)
3
average_tie_strength(D)
3.0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment