[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [igraph] Python: Converting large, sparse network from Scipy to Igra

From: Alacast
Subject: Re: [igraph] Python: Converting large, sparse network from Scipy to Igraph
Date: Wed, 3 Jul 2013 12:35:28 -0400


For future users, it looks like this:

sources, targets = data.nonzero()
weights = data[sources, targets]
g = Graph(zip(sources, targets), directed=True, edge_attrs={'weight': weights})

On Wed, Jul 3, 2013 at 11:51 AM, Tamás Nepusz <address@hidden> wrote:
> data.toarray() converts the sparse matrix to dense/full format, which blows my memory out of the water. What ought I to be doing?
Use the nonzero() method of your sparse matrix to extract the row/column indices of the nonzero elements of your matrix, then construct the graph using the standard Graph() constructor which accepts an edge list. If you want to keep the weights as well, there should be a way in SciPy to extract the values of the nonzero elements in the same order (probably A[A.nonzero()] will do the trick) and then you can assign that vector to the "weight" attribute of your graph.

igraph-help mailing list

reply via email to

[Prev in Thread] Current Thread [Next in Thread]