使用
问题在于
唯一的其他选择似乎是将矩阵转换为密集格式 (
pytables
时,据我所知似乎不支持scipy.sparse
矩阵格式,因此要存储矩阵就需要进行一些转换,例如:def store_sparse_matrix(self):
grp1 = self.getFileHandle().createGroup(self.getGroup(), 'M')
self.getFileHandle().createArray(grp1, 'data', M.tocsr().data)
self.getFileHandle().createArray(grp1, 'indptr', M.tocsr().indptr)
self.getFileHandle().createArray(grp1, 'indices', M.tocsr().indices)
def get_sparse_matrix(self):
return sparse.csr_matrix((self.getGroup().M.data, self.getGroup().M.indices, self.getGroup().M.indptr))
问题在于
get_sparse
函数需要一些时间(从磁盘读取),而且如果我理解正确,还需要数据适配内存。唯一的其他选择似乎是将矩阵转换为密集格式 (
numpy array
),然后正常使用 pytables
。然而这似乎效率不高,虽然我想也许 pytables
会处理压缩?