igraph-help
[Top][All Lists]

Re: [igraph] Help required - How to perform matrix multiplication in igr

 From: Tamas Nepusz Subject: Re: [igraph] Help required - How to perform matrix multiplication in igraph-python Date: Tue, 12 Jan 2016 22:07:04 +0100

```Hello,

> I have a bipartite graph and i want to compute the square of the adjacency
> matrix.
> How to do it in igraph-python?
You don't ;) igraph-python is not designed for matrix operations. Your
best bet is to use a sparse matrix class from SciPy (Scientific
Python). NumPy probably won't be enough because NumPy matrices are
dense and they will be too slow for an IMDb data set (assuming that it
contains tens or hundreds of thousands of nodes). So, basically, you
take the edge list of the graph, convert it into a SciPy sparse matrix
(look for scipy.sparse.coo_matrix), and then perform the
multiplication using SciPy.

> I am analyzing IMDb data set where i have information about actor and movie.
> I want to find out which actors acted in a movie and which movies have
> common actors.
You don't need matrix multiplication for that. Just get the adjacency
list of the graph, convert each item in the adjacency list to a set,
and then perform set intersections:

neis = [set(x) for x in g.get_adjlist()]

Then neis[i].intersection(neis[j]) will give you the common neighbors
of nodes i and j.

You can also use bipartite_projection() - what's wrong with that?

T.

```