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.
You could check the class
m0=sparse.csc_matrix([1])
In [4]: type(m0).__name__
Out[4]: 'csc_matrix'
In [5]: isinstance(m0,sparse.csc_matrix)
Out[5]: True
In [6]: isinstance(m0,sparse.csr_matrix)
Out[6]: False
In [9]: sparse.isspmatrix_csc(m0)
Out[9]: True
In [10]: sparse.isspmatrix_csc??
...
def isspmatrix_csc(x):
return isinstance(x, csc_matrix)