File tree Expand file tree Collapse file tree 1 file changed +36
-0
lines changed
Expand file tree Collapse file tree 1 file changed +36
-0
lines changed Original file line number Diff line number Diff line change 1+ import numpy as np
2+ import h5py
3+
4+
5+ a = np .arange (1000 , dtype = np .float64 ).reshape (25 , 40 )
6+
7+ with h5py .File ("test.h5" , "w" ) as f :
8+
9+ # attributes are meta-data that can help describe the data
10+ # in h5py, they are dictionary keys
11+ f .attrs ["about" ] = "a test HDF5 file with h5py"
12+
13+ # groups can be thought of as subdirectories in the output file,
14+ # and can help you organize data together logically
15+ grp = f .create_group ("data" )
16+
17+ # a numpy array is a dataset in HDF5 -- it will figure out the
18+ # dimensions and type from the array itself
19+ grp .create_dataset ("a" , data = a )
20+
21+ # there can be attributes in the group too
22+ grp .attrs ["array info" ] = "a simple array"
23+
24+
25+ # now we'll try to read it in
26+ with h5py .File ("test.h5" , "r" ) as f :
27+
28+ # access the group we stored our data in
29+ g = f ["data" ]
30+
31+ aread = np .array (g ["a" ])
32+
33+
34+ # are they the same?
35+ da = a - aread
36+ print (np .max (abs (da )))
You can’t perform that action at this time.
0 commit comments