There is no direct function for this in igraph. However, note that len(g.neighbors(i)) is just the degree of vertex i, so you can call g.degree() , treat it as a 1D matrix using NumPy, and then multiply it by your own transpose st the column vector is multiplied by the row vector on the right. This gives you the preferred anchor score matrix:
from numpy import matrix d = matrix(g.degree()) pref_score_matrix = dT*d
Estimating common neighbors is more difficult using matrix notation, and in any case, I would not work with matrices if your graph is really large (even with 2000 vertices, you will have a matrix with 4 million elements). I would simply cache the representations of the set g.neighbors(i) for all possible values ββin the list, and then use them to calculate the general estimates of the neighbors, since the sets can intersect effectively:
neisets = [set(g.neighbors(i)) for i in xrange(g.vcount())] for v1, v2 in g.get_edgelist(): common_neis = neisets[v1].intersection(neisets[v2]) print "%d --> %d: %d" % (v1, v2, len(common_neis))
If you really want to stick with matrices, you can build an n by n matrix consisting of zeros only using the zeros function from NumPy, and then collapse the vertices once. Get all the neighbors of the vertices v and notice that any pair of neighbors of v has one neighbor: v:
from itertools import combinations from numpy import zeros n = g.vcount() common_neis = zeros(n, n) for v in xrange(g.vcount()): neis = g.neighbors(v) for u, w in combinations(neis, 2):
source share