File: array3.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 (47 lines) | stat: -rw-r--r-- 1,132 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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import numpy as np

import tables as tb

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

# Create a large array
# a = reshape(array(range(2**16), "s"), (2,) * 16)
a = np.ones((2,) * 8, np.int8)
print("About to write array a")
print("  with shape: ==>", a.shape)
print("  and dtype: ==>", a.dtype)

# Save it on the HDF5 file
hdfarray = fileh.create_array(root, "carray", a, "Large array")

# Get metadata on the previously saved array
print()
print("Info on the object:", repr(root.carray))

# Close the file
fileh.close()

# Open the previous HDF5 file in read-only mode
fileh = tb.open_file("array3.h5", mode="r")
# Get the root group
root = fileh.root

# Get metadata on the previously saved array
print()
print("Getting info on retrieved /carray object:", repr(root.carray))

# Get the actual array
# b = fileh.readArray("/carray")
# You can obtain the same result with:
b = root.carray.read()
print()
print("Array b read from file")
print("  with shape: ==>", b.shape)
print("  with dtype: ==>", b.dtype)
# print "  contents:", b

# Close the file
fileh.close()