擅长:python、mysql、java
<p>假设您的矩阵是稀疏矩阵,您需要<code>.getformat()</code>方法:</p>
<pre><code>In [70]: s = scipy.sparse.coo_matrix([1,2,3])
In [71]: s
Out[71]:
<1x3 sparse matrix of type '<type 'numpy.int32'>'
with 3 stored elements in COOrdinate format>
In [72]: s.getformat()
Out[72]: 'coo'
In [73]: s = scipy.sparse.csr_matrix([1,2,3])
In [74]: s
Out[74]:
<1x3 sparse matrix of type '<type 'numpy.int32'>'
with 3 stored elements in Compressed Sparse Row format>
In [75]: s.getformat()
Out[75]: 'csr'
</code></pre>