【问题标题】:scipy large sparse matrixscipy大稀疏矩阵
【发布时间】:2012-03-13 14:50:36
【问题描述】:

我正在尝试使用大型 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 分布)

【问题讨论】:

    标签: python scipy


    【解决方案1】:

    这是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))
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-11-16
      • 2017-02-17
      • 2017-03-26
      • 2017-03-31
      • 2023-04-10
      • 1970-01-01
      • 2017-07-21
      • 2011-11-28
      相关资源
      最近更新 更多