Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Checking if a scipy sparse matrix is CSC or CSR

I would like to know the best way to check if a scipy sparse matrix, if CSC or CSR. Right now I'm using.

rows, cols = X.shape()
indptr = X.indptr()
if len(indptr) == cols + 1:
    print "csc"
else:
    print "csr"

Thanks.

like image 750
Manoj Avatar asked Oct 20 '25 21:10

Manoj


1 Answers

It looks like you could use the .getformat() method:

>>> m0 = scipy.sparse.csc_matrix([1])
>>> m0.getformat()
'csc'
>>> m1 = scipy.sparse.csr_matrix([1])
>>> m1.getformat()
'csr'
like image 157
DSM Avatar answered Oct 23 '25 09:10

DSM



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!