fork download
  1. import itertools
  2. def l(a,i,r):
  3. s=[b for b in r if a[i][b]]
  4. k=len(s)
  5. return 2.0*sum(map(lambda x:a[x[0]][x[1]],itertools.combinations(s,2)))/k/(k-1)
  6. def g(a):
  7. n=len(a)
  8. r=range(n)
  9. return sum([l(a,i,r) for i in r])/n
  10.  
  11. print g([[0,1,1],
  12. [1,0,0],
  13. [1,0,0]])
Runtime error #stdin #stdout 0.09s 10840KB
stdin
Standard input is empty
stdout
Standard output is empty