我正在尝试使用大型 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 内存和 entthought 分布的 macbook air)
最佳答案
这是 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))
关于python - scipy 大型稀疏矩阵,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9671150/