File: h5_string.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 (29 lines) | stat: -rw-r--r-- 706 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
#
# This example creates an HDF5 file string.h5 and DSfixed dataset in it.
# Then it opens the file and reads data back.
#
import h5py
import numpy as np
#
# Create a new file using default properties.
#
file = h5py.File('string.h5','w')
#
# Create a dataset under the Root group using variable-length string type.
#

fixed_string = np.dtype('a10')
dataset = file.create_dataset("DSfixed",(4,), dtype=fixed_string)
data = ("Parting   ", ".is such  ", ".sweet    ", ".sorrow...")
dataset[...] = data
#
# Close the file before exiting
#
file.close()
file = h5py.File('string.h5', 'r')
dataset = file['DSfixed']
data_out = dataset[...]
for i in range(4):	
    print("DSfixed[i] = ",data_out[i])

file.close()