File: vlarray3.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 (28 lines) | stat: -rw-r--r-- 591 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
#!/usr/bin/env python3

"""Example that shows how to easily save a variable number of atoms with a
VLArray."""

import numpy as np

import tables as tb

N = 100
shape = (3, 3)

np.random.seed(10)  # For reproductible results
f = tb.open_file("vlarray3.h5", mode="w")
vlarray = f.create_vlarray(
    f.root, "vlarray1", tb.Float64Atom(shape=shape), "ragged array of arrays"
)

k = 0
for i in range(N):
    lines = []
    for j in range(np.random.randint(N)):
        lines.append(np.random.randn(*shape))
        k += 1
    vlarray.append(lines)

print("Total number of atoms:", k)
f.close()