dgl.DGLGraph.from_scipy_sparse_matrix

DGLGraph.from_scipy_sparse_matrix(spmat)[source]

Convert from scipy sparse matrix.

Parameters:spmat (scipy sparse matrix) – The graph’s adjacency matrix

Examples

>>> from scipy.sparse import coo_matrix
>>> row = np.array([0, 3, 1, 0])
>>> col = np.array([0, 3, 1, 2])
>>> data = np.array([4, 5, 7, 9])
>>> a = coo_matrix((data, (row, col)), shape=(4, 4))
>>> g = dgl.DGLGraph()
>>> g.from_scipy_sparse_matrix(a)