It does not matter whether or not the graph is sparse, because igraph will still create a dense matrix, so that it performs operations O (n 2). (Technically, the matrix is created in the C layer, wherein the initialization of the matrix to all zeros takes O (n 2), and then it is filled units in O (m), where n is the number of vertices and m - number of ribs, but then the matrix is forwarded to the level Python, where it is converted into a matrix object and Python layer has no idea that the matrix significantly sparse, however requires O (n 2) to convert it. on my laptop creating an adjacency matrix for the graph 3000 nodes is about 500 ms and I think it's probably fine.
Yes, there is a way to create a sparse matrix of the graph chart, although it's a bit long-winded:
from scipy.sparse import coo_matrix from numpy import hstack, ones def graph_to_sparse_matrix(graph): xs, ys = map(array, zip(*graph.get_edgelist())) if not graph.is_directed(): xs, ys = hstack((xs, ys)).T, hstack((ys, xs)).T else: xs, ys = xs.T, ys.T return coo_matrix((ones(xs.shape), (xs, ys))) zip (* graph.get_edgelist ())) from scipy.sparse import coo_matrix from numpy import hstack, ones def graph_to_sparse_matrix(graph): xs, ys = map(array, zip(*graph.get_edgelist())) if not graph.is_directed(): xs, ys = hstack((xs, ys)).T, hstack((ys, xs)).T else: xs, ys = xs.T, ys.T return coo_matrix((ones(xs.shape), (xs, ys))) , ys)). T, hstack ((ys, xs)). T from scipy.sparse import coo_matrix from numpy import hstack, ones def graph_to_sparse_matrix(graph): xs, ys = map(array, zip(*graph.get_edgelist())) if not graph.is_directed(): xs, ys = hstack((xs, ys)).T, hstack((ys, xs)).T else: xs, ys = xs.T, ys.T return coo_matrix((ones(xs.shape), (xs, ys)))