Public
Snippet $267 authored by Kirill Smelkov

Example of 3D ZBigArray append (item is just np.int)

Edited
3dappend.py
#!/usr/bin/env python
# 3dappend.py - this program demonstrates using ZBigArray append with 3D arrays

from __future__ import print_function

from wendelin.bigarray.array_zodb import ZBigArray
from wendelin.lib.zodb import dbopen, dbclose
import transaction

import numpy as np


def main():
    # init db
    root = dbopen('test.fs')

    # create Nx2x3 array; initially N=0
    A = ZBigArray((0, 2,3), np.int)
    root['A'] = A
    transaction.commit()

    # append 2D slices to A in a loop
    for i in range(5):
        # values inside 2D slice will be N + small
        # this way it is easy to track where a slice is in major dimensions from element value
        n = 100*i

        s = np.array([[n+0,n+1,n+2], [n+10,n+11,n+12]], dtype=np.int)
        print('\n' + '-'*20)
        print('appending %s:' % (s.shape,))
        print(s)
        print()

        A.append(s[np.newaxis, ...])
        print('A %s:' % (A.shape,))
        print(A[:])


if __name__ == '__main__':
    main()