小编Ofe*_*fey的帖子

如何在scipy中创建一个巨大的稀疏矩阵

我正在尝试创建一个非常庞大的稀疏矩阵,它具有一个形状(447957347, 5027974).并且,它包含3,289,288,566个元素.

但是,当我创建一个csr_matrix使用时scipy.sparse,它会返回如下内容:

<447957346x5027974 sparse matrix of type '<type 'numpy.uint32'>'
    with -1005678730 stored elements in Compressed Sparse Row format>
Run Code Online (Sandbox Code Playgroud)

创建矩阵的源代码是:

indptr = np.array(a, dtype=np.uint32)    # a is a python array('L') contain row index information
indices = np.array(b, dtype=np.uint32)   # b is  a python array('L') contain column index information
data = np.ones((len(indices),), dtype=np.uint32)
test = csr_matrix((data,indices,indptr), shape=(len(indptr)-1, 5027974), dtype=np.uint32)
Run Code Online (Sandbox Code Playgroud)

而且,我还发现当我将一个30亿长度的python数组转换为numpy数组时,它会引发一个错误:

ValueError:setting an array element with a sequence
Run Code Online (Sandbox Code Playgroud)

但是,当我创建三个10亿个长度的python数组,并将它们转换为numpy数组时,然后追加它们.它工作正常.

我糊涂了.

python arrays numpy scipy sparse-matrix

7
推荐指数
1
解决办法
1096
查看次数

标签 统计

arrays ×1

numpy ×1

python ×1

scipy ×1

sparse-matrix ×1