[英]Scipy large sparse array dimensions MemoryError
我正在使用 scipy.sparse 处理相对较大的高维稀疏scipy.sparse
。 实际数据和行/列索引不存在存储问题。
问题是我最终得到了类似的东西
sp.csr_matrix(([1], ([0], [0])), shape=(int(1e14), 1)).shape
这使
MemoryError: Unable to allocate 728. TiB for an array with shape (100000000000001,) and data type int64
因为它看起来像scipy
试图分配行/列掩码(或什么?)
有没有好的解决方法? 使用coo_matrix
会修复它吗?
事实证明我只是个白痴,应该更加注意我使用的是 CSC 矩阵还是 CSR 矩阵。
CSC 将压缩行。 CSR 将压缩列。 对于像这样存储的数据(我确信这是一种利用稀疏性的糟糕格式),CSC 会更好地工作。
无论如何,这两个都可以正常工作
wat = sp.csc_matrix(([1], ([0], [0])), shape=(int(1e14), 1))
wat2 = sp.csr_matrix(([1], ([0], [0])), shape=(1, int(1e14)))
这只是对CSC和CSR为我们所做的事情的误解
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.