scipy.sparse.issparse is used in this post.
Is it possible to specify your own distance function using scikit-learn K-Means Clustering?
However, I have no idea how it works. I already find the document, which is empty. http://docs.scipy.org/doc/scipy/reference/generated/scipy.sparse.issparse.html
from scipy.sparse import issparse
issparse([0, 0, 0])
>> False
issparse([[1, 0, 0], [0, 0, 0]])
>> False
It always return False. How can I make it return True?
issparse has nothing to do with how many elements the input has. Rather, scipy.sparse defines a number of types optimized for representing sparse matrices, and issparse determines whether the input is a sparse matrix object.
In [1]: import scipy.sparse
In [2]: scipy.sparse.issparse(scipy.sparse.bsr_matrix([[1, 0], [0, 1]]))
Out[2]: True
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With