File: attributes1.py

package info (click to toggle)
pytables 3.10.2-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 15,228 kB
  • sloc: ansic: 82,212; python: 65,296; cpp: 753; sh: 394; makefile: 100
file content (33 lines) | stat: -rw-r--r-- 637 bytes parent folder | download | duplicates (2)
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
32
33
import numpy as np

import tables as tb

# Open a new empty HDF5 file
fileh = tb.open_file("attributes1.h5", mode="w", title="Testing attributes")
# Get the root group
root = fileh.root

# Create an array
a = np.array([1, 2, 4], np.int32)
# Save it on the HDF5 file
hdfarray = fileh.create_array(root, "array", a, "Integer array")

# Assign user attributes

# A string
hdfarray.attrs.string = "This is an example"

# A Char
hdfarray.attrs.char = "1"

# An integer
hdfarray.attrs.int = 12

# A float
hdfarray.attrs.float = 12.32

# A generic object
hdfarray.attrs.object = {"a": 32.1, "b": 1, "c": [1, 2]}

# Close the file
fileh.close()