<p>在<a href="https://github.com/scipy/scipy/blob/v1.1.0/scipy/sparse/construct.py#L434-L464" rel="nofollow noreferrer">^{<cd1>}</a>的源代码中,它调用<a href="https://github.com/scipy/scipy/blob/v1.1.0/scipy/sparse/construct.py#L501-L622" rel="nofollow noreferrer">^{<cd2>}</a>,如果没有建立快速路径用例,它在其中<strong>可能</strong>将矩阵转换为<code>coo_matrix</code>。在</p>
<hr/>
<p><strong>诊断</strong></p>
<blockquote>
<p>Looking at the scipy code I understand it will not do any conversion
if the input matrices are <code>csr_matrix</code> objects.</p>
</blockquote>
<p>在<code>bat</code>的<a href="https://github.com/scipy/scipy/blob/v1.1.0/scipy/sparse/construct.py#L501-L622" rel="nofollow noreferrer">source code</a>中,除了两个矩阵是<code>csr_matrix</code>之外,实际上还有更多的条件,才能使它变成<code>coo_matrix</code>对象。看到源代码,需要满足以下两个条件之一</p>
<pre><code># check for fast path cases
if (N == 1 and format in (None, 'csr') and all(isinstance(b, csr_matrix)
for b in blocks.flat)):
...
elif (M == 1 and format in (None, 'csc')
and all(isinstance(b, csc_matrix) for b in blocks.flat)):
...
</code></pre>
<p>在要调用的<a href="https://github.com/scipy/scipy/blob/v1.1.0/scipy/sparse/construct.py#L573" rel="nofollow noreferrer"><strong>line 573</strong></a><code>A = coo_matrix(blocks[i,j])</code>之前。在</p>
<hr/>
<p><strong>建议</strong></p>
<p>为了解决这个问题,我建议您再检查一下是否满足<code>csr_matrix</code>或{<cd9>}(上面列出的两个条件)的快速路径情况。请查看<code>bat</code>的完整源代码以获得更好的理解。如果不满足条件,则会将您转发到将矩阵转换为<code>coo_matrix</code>。在</p>