我正在尝试创建一个非常庞大的稀疏矩阵,它具有一个形状(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数组时,然后追加它们.它工作正常.
我糊涂了.