> Is there a function to write a sparse adjacency matrix of a graph to a > file? I see "write_adjacency" but the docs don't indicate it gives a > sparse matrix. It won't - it would give you a dense matrix. Producing a SciPy sparse matrix with a single command is not possible (because we would have to link igraph to SciPy at compile time if we wanted to do that), but it's only a few lines of code:
import numpy as np from scipy.sparse import coo_matrix sources, targets = zip(*graph.get_edgelist()) vcount = graph.vcount() data = np.array([1] * graph.ecount()) rows = np.array(sources, dtype=np.int32, copy=False) cols = np.array(targets, dtype=np.int32, copy=False) matrix = coo_matrix((data, (rows, cols)), shape=(vcount, vcount)) If your graph is undirected, then this will store only the upper half of it, so you also need to do this: matrix += matrix.T (This will probably convert the matrix into compressed sparse row format as a side-effect). T. _______________________________________________ igraph-help mailing list [email protected] https://lists.nongnu.org/mailman/listinfo/igraph-help
