{ } Raw JSON

bundles / scipy 1.18.0 / scipy / _lib / _sparse / issparse

function

scipy._lib._sparse:issparse

source: /scipy/_lib/_sparse.py:10

Signature

def issparse(x)

Summary

Is x either sparse array or sparse matrix type?

Parameters

x : object

object to check for being a sparse array or a sparse matrix

Returns

: bool

True if x is a sparse array or a sparse matrix, False otherwise

Notes

Use sp.sparse.isspmatrix(x) or isinstance(x, sp.sparse.sparray) to check between sparray or spmatrix. Use a.format to check the sparse format, e.g. a.format == 'csr'.

Examples

import numpy as np
from scipy.sparse import csr_array, csr_matrix, issparse
issparse(csr_matrix([[5]]))
issparse(csr_array([[5]]))
issparse(np.array([[5]]))
issparse(5)
✓
False

Aliases

  • scipy.sparse.issparse

Referenced by