点积可以执行多大的 scipy.csr_matrix 矩阵?



我正在尝试使用大型数组执行点积

L_mat=csr_matrix(L_mat)
# L_mat is (24, 1226880)
L_mat_t=csr_matrix(L_mat_t)
# L_mat_t is (1226880, 24)
# Following is possible?
LT_dot_L=L_mat_t.dot(L_mat)
# I'm expecting (1226880, 1226880) but when I did this, 
# I got MemoryError

当我执行较小的数组时,我得到了相同的内存错误

(523776, 24) dot (24, 523776)

这可以执行

(24, 523776) dot (523776, 24) = (24, 24)

如何使用csr_matrix或其他方式执行大阵列点积?

我不会尝试内存错误,但请考虑此测试

In [300]: from scipy import sparse
In [301]: M = sparse.random(10,10000, format='csr')
In [302]: M
Out[302]: 
<10x10000 sparse matrix of type '<class 'numpy.float64'>'
with 1000 stored elements in Compressed Sparse Row format>
In [303]: M.dot(M.T)
Out[303]: 
<10x10 sparse matrix of type '<class 'numpy.float64'>'
with 66 stored elements in Compressed Sparse Row format>
In [304]: M.T.dot(M)
Out[304]: 
<10000x10000 sparse matrix of type '<class 'numpy.float64'>'
with 100310 stored elements in Compressed Sparse Column format>

M稀疏性为 0.01,Out[304]为 .001,但仍有 100 倍以上的非零值。 使用(1226880,1226880(矩阵,我可以很容易地想象出一个不适合内存的矩阵,即使它是稀疏的。

最新更新