简体   繁体   English

Scipy 大稀疏数组维度 MemoryError

[英]Scipy large sparse array dimensions MemoryError

I'm working with relatively large high-dimensional sparse arrays using scipy.sparse .我正在使用 scipy.sparse 处理相对较大的高维稀疏scipy.sparse The actual data and row/column indices are no issue to store.实际数据和行/列索引不存在存储问题。

The problem is I end up up with things like问题是我最终得到了类似的东西

sp.csr_matrix(([1], ([0], [0])), shape=(int(1e14), 1)).shape

which gives这使

MemoryError: Unable to allocate 728. TiB for an array with shape (100000000000001,) and data type int64

since it looks like scipy tries to allocate row/column masks (or something?)因为它看起来像scipy试图分配行/列掩码(或什么?)

Is there a good workaround for this?有没有好的解决方法? Would using coo_matrix fix it?使用coo_matrix会修复它吗?

Update更新

It turns out I'm just an idiot and should have paid better attention to whether I was using a CSC matrix or CSR matrix.事实证明我只是个白痴,应该更加注意我使用的是 CSC 矩阵还是 CSR 矩阵。

CSC will compress the rows. CSC 将压缩行。 CSR will compress the columns. CSR 将压缩列。 For data stored like this (in what I am sure is a terrible format for making use of sparsity), CSC will work way better.对于像这样存储的数据(我确信这是一种利用稀疏性的糟糕格式),CSC 会更好地工作。

In any case, both of these work fine无论如何,这两个都可以正常工作

wat = sp.csc_matrix(([1], ([0], [0])), shape=(int(1e14), 1))
wat2 = sp.csr_matrix(([1], ([0], [0])), shape=(1, int(1e14)))

and this is just a misunderstanding of what CSC and CSR do for us这只是对CSC和CSR为我们所做的事情的误解

If you are using 32bit version of python, please upgrade to 64bit (in case you have 64 bit hardware and OS).如果您使用的是 32 位版本的 python,请升级到 64 位(如果您有 64 位硬件和操作系统)。 Further, it is memory error where your system available memory is not sufficient to handle a huge allocation (100000000000001,) .此外,这是 memory 错误,您的系统可用 memory 不足以处理大量分配(100000000000001,)

How much RAM is available at your system.您的系统有多少可用 RAM。 If you can add more description about your system such as OS, RAM etc will be helpful.如果您可以添加更多关于您的系统的描述,例如操作系统、RAM 等,将会很有帮助。

See the link following related links with somehow (not exactly) the same issue Link 1 Link 2请参阅以下相关链接的链接,以某种方式(不完全)相同的问题链接 1 链接 2

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM