Skip to content

Instantly share code, notes, and snippets.

@plotti
Created May 24, 2012 14:42
Show Gist options
  • Save plotti/2781968 to your computer and use it in GitHub Desktop.
Save plotti/2781968 to your computer and use it in GitHub Desktop.
def reciprocity(D):
G=D.to_undirected() # copy
for (u,v) in D.edges():
if not D.has_edge(v,u):
G.remove_edge(u,v)
return float(len(G.edges()))/len(D.to_undirected().edges())
# A simple test:
G = nx.DiGraph()
G.add_nodes_from([1,2,3])
G.add_edges_from([(1,2),(2,1),(2,3)])
reciprocity(G)
0.5
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment