Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How does "scipy.sparse.issparse" work? It always return "False"

Tags:

python

scipy

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?

like image 596
akiniwa Avatar asked Feb 07 '26 00:02

akiniwa


1 Answers

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
like image 177
user2357112 supports Monica Avatar answered Feb 13 '26 19:02

user2357112 supports Monica



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!