Created
December 7, 2021 13:01
-
-
Save delijati/aa9bf137283fb05f79b7866c54de0e13 to your computer and use it in GitHub Desktop.
Safe metadata and multiple datasets (pure numpy basiclly pickle)
This file contains hidden or 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 numpy as np | |
SIZE = 500000 | |
meta = {} | |
first = np.random.random(SIZE) | |
meta["first"] = {"git id": "yay this is a string"} | |
second = np.random.random(SIZE) | |
meta["second"] = {"git id": "yay this is a string"} | |
third = np.random.random(SIZE) | |
meta["third"] = {"wo": [1, 2, 3, 4, 5], "bla": "terrow"} | |
np.savez_compressed("test.npz", first=first, second=second, third=third, metadata=meta) | |
data = np.load("test.npz", allow_pickle=True) | |
metadata = data["metadata"][()] # Read a 0-dimensional array | |
print("Keys: %s" % data.keys()) | |
for k in data.keys(): | |
if k == "metadata": | |
continue | |
print("Data: %s" % data[k]) | |
print("Attr: %s" % metadata[k].keys()) | |
for ak in metadata[k].keys(): | |
print("Attr val: %s" % metadata[k][ak]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment