Created
September 26, 2018 05:32
-
-
Save zaburo-ch/ee5bcb7f596ad565d9d93107608750e1 to your computer and use it in GitHub Desktop.
save_arrayボツ案
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
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