Skip to content

Instantly share code, notes, and snippets.

@zaburo-ch
Created September 26, 2018 05:32
Show Gist options
  • Save zaburo-ch/ee5bcb7f596ad565d9d93107608750e1 to your computer and use it in GitHub Desktop.
Save zaburo-ch/ee5bcb7f596ad565d9d93107608750e1 to your computer and use it in GitHub Desktop.
save_arrayボツ案
def save_array(X, filepath):
X = np.asarray(X)
shape_str = str(X.shape)
pd.Series(X.reshape(-1)).to_hdf(filepath, complevel=9, complib='blosc', key=shape_str)
def load_array(filepath):
with pd.io.pytables.HDFStore(filepath, mode='r') as store:
assert len(store.keys()) == 1
print(store.keys())
key = store.keys()[0]
assert re.match(r'/\(\d+(,|(,\s?\d+)*)\)', key)
shape = tuple([int(v) for v in '/(0, 5)'[2:-1].split(',') if v != ''])
return store.select(key).values.reshape(shape)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment