Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 7th, 2012  |  syntax: None  |  size: 0.52 KB  |  hits: 14  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Using pytables, which is more efficient: scipy.sparse or numpy dense matrix?
  2. def store_sparse_matrix(self):
  3.     grp1 = self.getFileHandle().createGroup(self.getGroup(), 'M')
  4.     self.getFileHandle().createArray(grp1, 'data', M.tocsr().data)
  5.     self.getFileHandle().createArray(grp1, 'indptr', M.tocsr().indptr)
  6.     self.getFileHandle().createArray(grp1, 'indices', M.tocsr().indices)
  7.  
  8. def get_sparse_matrix(self):
  9.     return sparse.csr_matrix((self.getGroup().M.data, self.getGroup().M.indices, self.getGroup().M.indptr))