Skip to content

Instantly share code, notes, and snippets.

@prerakmody
Last active June 2, 2018 06:15
Show Gist options
  • Save prerakmody/fed4240a46eb9d5e4f912c1fdddd5041 to your computer and use it in GitHub Desktop.
Save prerakmody/fed4240a46eb9d5e4f912c1fdddd5041 to your computer and use it in GitHub Desktop.
Hacks with the HDF5 format using h5py
import h5py
import numpy as np
filename = 'filename.h5'
data = h5py.File(filename)
nodes = list(data.items())
data_path= '/a/b' #mention the node you are interested in
#Convert to .csv
filename_save = 'filename.csv'
np.savetxt(filename_save, data[data_path], delimiter=',')
import numpy as np
## Saves a .npy file
X = np.ones((5,5))
y = np.ones((3,3))
url_npz = 'data_npy/train_{0}'.format('%.5d' % (i))
np.savez_compressed(url_npz, X=X, Y=Y)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment