Scipy大型稀疏矩阵

3

我正在尝试使用大型的10^5x10^5稀疏矩阵,但好像遇到了scipy的问题:

n = 10 ** 5
x = scipy.sparse.rand(n, n, .001)

获取

ValueError: Trying to generate a random sparse matrix such as the
    product of dimensions is greater than 2147483647 - this is not
    supported on this machine

有人知道为什么会有限制吗,我能否避免它?(顺便说一下,我使用的是4GB内存的MacBook Air和Enthought发行版)

1个回答

10

这是一种限制,是由于scipy.sparse.rand()的实现方式导致的。您可以自己编写随机矩阵生成代码来避免这种限制:

n = 10 ** 5
density = 1e-3
ij = numpy.random.randint(n, size=(2, n * n * density))
data = numpy.random.rand(n * n * density)
matrix = scipy.sparse.coo.coo_matrix((data, ij), (n, n))

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接