Created
January 16, 2017 18:15
-
-
Save hiropppe/4254d92374b72a2383901745410ea107 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import tables as tb | |
from scipy.sparse import lil_matrix | |
h5 = tb.open_file('sparse.h5', 'a') | |
data_group = h5.create_group(h5.root, 'data_group') | |
indices_group = h5.create_group(h5.root, 'indices_group') | |
indptr_group = h5.create_group(h5.root, 'indptr_group') | |
for i in xrange(10000): | |
name = 'm{:d}'.format(i) | |
m = lil_matrix((361, 200000)) | |
for j in xrange(10): | |
m[i % 361, j] = 1 | |
m = m.tocsr() | |
data = m.data | |
data_atom = tb.Atom.from_dtype(data.dtype) | |
data_store = h5.create_carray(data_group, name, data_atom, data.shape) | |
data_store[:] = data | |
indices = m.indices | |
indices_atom = tb.Atom.from_dtype(indices.dtype) | |
indices_store = h5.create_carray(indices_group, name, indices_atom, indices.shape) | |
indices_store[:] = indices | |
indptr = m.indptr | |
indptr_atom = tb.Atom.from_dtype(indptr.dtype) | |
indptr_store = h5.create_carray(indptr_group, name, indptr_atom, indptr.shape) | |
indptr_store[:] = indptr | |
h5.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment