File: h5_readtofloat.py

package info (click to toggle)
hdf5 1.14.5%2Brepack-3
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 208,856 kB
  • sloc: ansic: 715,772; f90: 42,941; java: 38,102; sh: 30,925; xml: 18,706; cpp: 18,011; makefile: 2,423; perl: 2,383; yacc: 332; python: 262; javascript: 203; lex: 157; ruby: 24; csh: 22
file content (31 lines) | stat: -rw-r--r-- 863 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#
# This example reads integer data from dset.h5 file into Python floatng buffers.
#
import h5py
import numpy as np
#
# Open an existing file using default properties.
#
file = h5py.File('dset.h5','r+')
#
# Open "dset" dataset under the root group.
#
dataset = file['/dset']
#
# Initialize buffers,read and print data.
#
# Python float type is 64-bit, one needs to use NATIVE_DOUBLE HDF5 type to read data. 
data_read64 = np.zeros((4,6,), dtype=float)
dataset.id.read(h5py.h5s.ALL, h5py.h5s.ALL, data_read64, mtype=h5py.h5t.NATIVE_DOUBLE)
print("Printing data 64-bit floating numbers...")
print(data_read64)

data_read32 = np.zeros((4,6,), dtype=np.float32)
dataset.id.read(h5py.h5s.ALL, h5py.h5s.ALL, data_read32, mtype=h5py.h5t.NATIVE_FLOAT)
print("Printing data 32-bit floating numbers...")
print(data_read32)
#
# Close the file before exiting
#
file.close()