dgl.DGLGraph.from_scipy_sparse_matrix

DGLGraph.from_scipy_sparse_matrix(spmat, multigraph=None)[source]

Convert from scipy sparse matrix.

Parameters:
  • spmat (scipy sparse matrix) – The graph’s adjacency matrix
  • multigraph (bool, optional) – Deprecated (Will be deleted in the future). Whether the graph would be a multigraph. If the input scipy sparse matrix is CSR, this argument is ignored.

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)