DOK.from_scipy_sparse

classmethod DOK.from_scipy_sparse(x, /, *, fill_value=None)[source]

Create a DOK array from a scipy.sparse.spmatrix.

Parameters:
  • x (scipy.sparse.spmatrix) – The matrix to convert.

  • fill_value (scalar) – The fill-value to use when converting.

Returns:

The equivalent DOK array.

Return type:

DOK

Examples

>>> x = scipy.sparse.rand(6, 3, density=0.2)
>>> s = DOK.from_scipy_sparse(x)
>>> np.array_equal(x.todense(), s.todense())
True