Skip to content

Instantly share code, notes, and snippets.

@nhannguyen95
Created June 7, 2018 12:12
Show Gist options
  • Save nhannguyen95/5c9367f947f0e8367e12c73f2e3528d3 to your computer and use it in GitHub Desktop.
Save nhannguyen95/5c9367f947f0e8367e12c73f2e3528d3 to your computer and use it in GitHub Desktop.
HDF5 read & write
import h5py
f = h5py.File('path/to/file', 'r')
# List all groups
print('Keys: %s' % f.keys())
# Get data
key = 'random_data'
random_data = np.asarray(f[key])
f.close()
import h5py
# Create random data
random_data = np.random.rand(2,2)
# Save data to HDF5
f = h5py.File('path/to/file', 'w')
f.create_dataset('random_data', data=random_data)
f.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment