【发布时间】:2017-02-17 14:04:12
【问题描述】:
构建 scipy 稀疏矩阵的最佳方法之一是使用 coo_matrix 方法,即。
coo_matrix((data, (i, j)), [shape=(M, N)])
where:
data[:] are the entries of the matrix, in any order
i[:] are the row indices of the matrix entries
j[:] are the column indices of the matrix entries
但是,如果矩阵非常大,将整个 i、j 和数据向量加载到内存中是不切实际的。
你如何构建一个 coo_matrix 使得 (data, (i, j)) 由磁盘提供(使用迭代器或生成器)并且磁盘上的数组/向量对象是 .npy 或 pickle 格式?
Pickle 是更好的选择,因为 numpy.save/load 没有针对 scipy sparse 进行优化。也许还有另一种更快的格式。
numpy.genfromtext() 和 numpy.loadtxt() 都很笨重、速度慢且占用内存。
【问题讨论】:
标签: scipy sparse-matrix