Databases Reference
In-Depth Information
>>> out . dtype
dtype('float64')
This process is very efficient; HDF5 only reads the fields you request from disk. Likewise,
you can choose to “update” only those fields you wish. If we were to set all the temper‐
atures we just read to a new value and write back out:
>>> out [ ... ] = 98.6
>>> dset [ "temp" , 90 : 100 ] = out
HDF5 updates only the temp field in each record. So if, for example, you want to modify
only the temperature or pressure part of the dataset, you can cut your memory use by
a factor of three.
Complex Numbers
Both NumPy and Python itself support complex numbers . These objects consist of two
floating-point numbers pasted together, one representing the real part, and one the
imaginary part of the number. In NumPy, you can have single precision (8 bytes total),
double precision (16 bytes total), or extended precision (24 bytes total):
>>> dset = f . create_dataset ( 'single_complex' , ( 100 ,), dtype = 'c8' )
While HDF5 has no out-of-the-box representation for complex numbers, a standard of
sorts has arisen, to which h5py adheres. Complex numbers are stored as a two-element
compound, the real part labelled r , and the imaginary part labelled i . Keep this in mind
if you want to access the data in other programs like IDL or MATLAB. Here's what the
dataset we created looks like with h5ls :
Opened "test.hdf5" with sec2 driver.
/ Group
Location: 1:96
Links: 1
/single_complex Dataset {100/100}
Location: 1:800
Links: 1
Storage: 800 logical bytes, 0 allocated bytes
Type: struct {
"r" +0 native float
"i" +4 native float
} 8 bytes
Enumerated Types
Those of you who have used C will recognize this next datatype. In the HDF5 world,
enumerated types or enums are integer datatypes for which certain values are associated
with text tags. For example, for a dataset of type np.uint8 you might define 0 to mean
RED , 1 to mean GREEN , and 2 to mean BLUE .
Search WWH ::




Custom Search