Skip to content

Instantly share code, notes, and snippets.

@alexlenail
Created July 9, 2022 18:55
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 alexlenail/250b945ee749a41d06a5fc4bff5ef012 to your computer and use it in GitHub Desktop.
Save alexlenail/250b945ee749a41d06a5fc4bff5ef012 to your computer and use it in GitHub Desktop.
import h5py
import numpy as np
def read_h5_to_dict(h5_path):
out_dict = {}
def add_h5_node_to_dict(name, node, out_dict=out_dict):
fullname = node.name
if isinstance(node, h5py.Dataset):
out_dict[fullname] = np.array(node)
with h5py.File(h5_path) as h5f:
h5f.visititems(add_h5_node_to_dict) # https://docs.h5py.org/en/latest/high/group.html#h5py.Group.visititems
return out_dict
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment