[英]Exporting Eigen csr_matrix to python via Pybind11 without converting to scipy.sparse.csc/csr matrix
[英]Checking if a scipy sparse matrix is CSC or CSR
我想知道檢查scipy稀疏矩陣的最佳方法,如果是CSC或CSR。 現在我正在使用。
rows, cols = X.shape()
indptr = X.indptr()
if len(indptr) == cols + 1:
print "csc"
else:
print "csr"
謝謝。
看起來你可以使用.getformat()
方法:
>>> m0 = scipy.sparse.csc_matrix([1])
>>> m0.getformat()
'csc'
>>> m1 = scipy.sparse.csr_matrix([1])
>>> m1.getformat()
'csr'
你可以查看課程
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)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.