Skip to content

Instantly share code, notes, and snippets.

@delijati
Created December 7, 2021 13:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save delijati/aa9bf137283fb05f79b7866c54de0e13 to your computer and use it in GitHub Desktop.
Save delijati/aa9bf137283fb05f79b7866c54de0e13 to your computer and use it in GitHub Desktop.
Safe metadata and multiple datasets (pure numpy basiclly pickle)
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