1
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN""http://www.w3.org/TR/html4/loose.dtd">
5
>The VLArray class</TITLE
8
CONTENT="Modular DocBook HTML Stylesheet Version 1.79"><LINK
10
TITLE="PyTables User's Guide"
11
HREF="index.html"><LINK
13
TITLE="Library Reference"
14
HREF="c1381.html"><LINK
16
TITLE="The EArray class"
17
HREF="x4072.html"><LINK
19
TITLE="The UnImplemented class"
20
HREF="x4290.html"></HEAD
31
SUMMARY="Header navigation table"
43
> User's Guide: Hierarchical datasets in Python - Release 1.3.2</TH
59
>Chapter 4. Library Reference</TD
86
NAME="VLArrayClassDescr"
89
>Instances of this class represents array objects in the
90
object tree with the property that their rows can have a
98
(homogeneous) elements (called <SPAN
111
>). Variable length arrays (or
118
> for short), similarly to <SAMP
119
CLASS="computeroutput"
122
instances, can have only one dimension, and likewise
124
CLASS="computeroutput"
126
>, the compound elements (the
133
>) of the rows of <SAMP
134
CLASS="computeroutput"
137
fully multidimensional objects.
141
CLASS="computeroutput"
143
> provides methods to read/write data
144
from/to variable length array objects residents on disk.
145
Also, note that this object inherits all the public
146
attributes and methods that <SAMP
147
CLASS="computeroutput"
156
NAME="subsection4.13.1"
173
CLASS="computeroutput"
176
HREF="x4389.html#AtomClassDescr"
179
instance representing the shape, type and flavor
180
of the atomic objects to be saved.
189
>On iterators, this is the index of
199
>The total number of rows.
210
NAME="subsection4.13.2"
221
NAME="subsubsection4.13.2.1"
222
>4.13.2.1. getEnum()</A
225
NAME="VLArray.getEnum"
228
>Get the enumerated type associated with this array.
231
>If this array is of an enumerated type, the
233
CLASS="computeroutput"
236
HREF="x4983.html#EnumClassDescr"
238
>) is returned. If it is
239
not of an enumerated type, a <SAMP
240
CLASS="computeroutput"
251
NAME="subsubsection4.13.2.2"
252
>4.13.2.2. append(sequence, *objects)</A
255
NAME="VLArray.append"
258
>Append objects in the <SAMP
259
CLASS="computeroutput"
263
>This method appends the objects in the <SAMP
264
CLASS="computeroutput"
274
The type of individual objects must be compliant with
275
the type of atoms in the array.
276
In the case of variable length strings, the very string to append
278
CLASS="computeroutput"
283
>Example of use (code available in
285
CLASS="computeroutput"
286
>examples/vlarray1.py</SAMP
293
from numpy import * # or, from numarray import *
296
fileh = tables.openFile("vlarray1.h5", mode = "w")
297
vlarray = fileh.createVLArray(fileh.root, 'vlarray1',
298
tables.Int32Atom(flavor="numpy"),
299
"ragged array of ints", Filters(complevel=1))
300
# Append some (variable length) rows:
301
vlarray.append(array([5, 6]))
302
vlarray.append(array([5, 6, 7]))
303
vlarray.append([5, 6, 9, 8])
305
# Now, read it through an iterator:
307
print vlarray.name+"["+str(vlarray.nrow)+"]-->", x
314
>The output of the previous program looks like this:</P
317
> vlarray1[0]--> [5 6]
318
vlarray1[1]--> [5 6 7]
319
vlarray1[2]--> [5 6 9 8]
323
CLASS="computeroutput"
325
> argument is only retained
326
for backwards compatibility; please do <SPAN
341
NAME="subsubsection4.13.2.3"
342
>4.13.2.3. iterrows(start=None,
343
stop=None, step=1)</A
346
NAME="iterrowsVLArrayDescr"
349
>Returns an iterator yielding one row per iteration. If
350
a range is supplied (i.e. some of the <SPAN
369
> parameters are passed),
370
only the appropriate rows are returned. Else, all the
371
rows are returned. See also the <SAMP
372
CLASS="computeroutput"
375
special methods in <A
376
HREF="x4133.html#VLArraySpecialMethods"
379
shorter way to call this iterator.
382
>The meaning of the <SPAN
401
> parameters is the same as in the
403
CLASS="computeroutput"
405
> python function, except that
406
negative values of <SAMP
407
CLASS="computeroutput"
410
allowed. Moreover, if only <SAMP
411
CLASS="computeroutput"
414
specified, then <SAMP
415
CLASS="computeroutput"
419
CLASS="computeroutput"
421
>. If you do not specify neither
434
>, then all the rows in
435
the object are selected.
441
> for row in vlarray.iterrows(step=4):
442
print vlarray.name+"["+str(vlarray.nrow)+"]-->", row
450
NAME="subsubsection4.13.2.4"
451
>4.13.2.4. read(start=None, stop=None,
455
NAME="readVLArrayDescr"
458
>Returns the actual data in <SAMP
459
CLASS="computeroutput"
462
lengths of the different rows are variable, the returned
463
value is a python list, with as many entries as
464
specified rows in the range parameters.
467
>The meaning of the <SPAN
486
> parameters is the same as in the
488
CLASS="computeroutput"
490
> python function, except that
491
negative values of <SAMP
492
CLASS="computeroutput"
495
allowed. Moreover, if only <SAMP
496
CLASS="computeroutput"
499
specified, then <SAMP
500
CLASS="computeroutput"
504
CLASS="computeroutput"
506
>. If you do not specify neither
519
>, then all the rows in
520
the object are selected.
529
NAME="subsection4.13.3"
537
NAME="VLArraySpecialMethods"
540
>Following are described the methods that automatically
541
trigger actions when a <SAMP
542
CLASS="computeroutput"
545
accessed in a special way (e.g., <SAMP
546
CLASS="computeroutput"
549
will be equivalent to a call to
551
CLASS="computeroutput"
552
>vlarray.__getitem__(slice(2,5,None)</SAMP
560
NAME="subsubsection4.13.3.1"
561
>4.13.3.1. __iter__()</A
564
NAME="VLArray.__iter__"
567
>It returns the same iterator than
569
CLASS="computeroutput"
570
>VLArray.iterrows(0,0,1)</SAMP
571
>. However, this does
572
not accept parameters.</P
577
> result = [ row for row in vlarray ]
580
>Which is equivalent to:</P
583
> result = [ row for row in vlarray.iterrows() ]
591
NAME="subsubsection4.13.3.2"
592
>4.13.3.2. __getitem__(key)</A
595
NAME="VLArray.__getitem__"
598
>It returns the slice of rows determined by
600
CLASS="computeroutput"
602
>, which can be an integer index or an
603
extended slice. The returned value is a list of objects
605
CLASS="computeroutput"
606
>array.atom.type</SAMP
613
> list1 = vlarray[4]
614
list2 = vlarray[4:1000:2]
622
NAME="subsubsection4.13.3.3"
623
>4.13.3.3. __setitem__(keys, value)</A
626
NAME="VLArray.__setitem__"
629
>Updates a vlarray row described by <SAMP
630
CLASS="computeroutput"
634
CLASS="computeroutput"
636
>. Depending on the value
638
CLASS="computeroutput"
640
>, the action taken is different:
648
CLASS="computeroutput"
655
refers to the number of row to be modified. The
657
CLASS="computeroutput"
659
> object must be type and shape
660
compatible with the object that exists in the vlarray
666
CLASS="computeroutput"
673
first element refers to the row to be modified, and
674
the second element to the range (so, it can be an
675
integer or an slice) of the row that will be
676
updated. As above, the <SAMP
677
CLASS="computeroutput"
680
be type and shape compatible with the object specified
681
in the vlarray row <SPAN
700
CLASS="computeroutput"
702
> (codification UTF-8) or
704
CLASS="computeroutput"
706
> atoms, there is a problem: one can
707
only update values with <SPAN
714
than in the original row. With UTF-8 encoding this is
715
problematic because, for instance, '<SAMP
716
CLASS="computeroutput"
719
takes 1 byte, but '<SAMP
720
CLASS="computeroutput"
722
>' takes two. The same
723
applies when using <SAMP
724
CLASS="computeroutput"
727
when cPickle applies to a class instance (for example),
728
it does not guarantee to return the same number of bytes
729
than over other instance, even of the same class than
730
the former. These facts effectively limit the number of
731
objects than can be updated in <SAMP
732
CLASS="computeroutput"
740
> vlarray[0] = vlarray[0]*2+3
741
vlarray[99,3:] = arange(96)*2+3
742
# Negative values for start and stop (but not step) are supported
743
vlarray[99,-99:-89:2] = vlarray[5]*2+3
753
SUMMARY="Footer navigation table"
b'\\ No newline at end of file'