Hi Jon Olav,

A Saturday 13 June 2009 13:25:13 Jon Olav Vik escrigué:
> If I understand the question correctly, this has confused me too. The short
> answer may be:
> a = tbl[:]
> a = tbl[:].view(numpy.recarray)
> or for single rows:
> a = tbl[i]
> a = tbl[i:i+1].view(numpy.recarray)
>
> The various options all have the same a.dtype and allow named field access
> with a["label"]. However, "dotting" (a.label) only works with recarrays
> (numpy.recarray aka numpy.core.records.recarray). The biggest gotcha for me
> was that casting tbl[i] to recarray has no effect: You need tbl[i:i+1] to
> get dotted access to fields of a single record.
>
> It is somewhat confusing that
> type(tbl[i]) is numpy.void
> type(tbl[i:i+1]) is numpy.ndarray
> and that none of them are numpy.recarray.

This is intended and mimics the behaviour of NumPy:

In [12]: type(r[0])
Out[12]: <type 'numpy.void'>

In [13]: type(r[0:1])
Out[13]: <type 'numpy.ndarray'>

>
> It is also confusing that the term "record array" is used both for
> numpy.recarray and a numpy.ndarray with a compound dtype (i.e. nonempty
> a.dtype.names).
> http://docs.scipy.org/doc/numpy/user/basics.rec.html

Yeah, this confusion has been mainly due to the existence of two objects that 
are similar in NumPy, but with some differences.  The first one, a ndarray 
with a compound type, is implemented at C level, and is generally faster to 
build and deal with.  And the other, numpy.recarray, is a Python class that 
inherit from ndarray and adds more functionality to it, most specially the 
capability to access fields as members of the array, using ``recarr.x`` and 
``recarr.y``.  However, it is more expensive to build.

Lately, it seems that the NumPy crew has stuck with the term ``structured 
arrays`` for naming the ndarray with a compound type, and ``record array`` (or 
``recarray``, for short) to the Python ``recarray`` class.

For what is worth, in general, PyTables always returns ``structured arrays`` 
as they are cheaper to build.  For people preferring the functionality of 
``record arrays`` instead, they can always build a view, as you are doing.

Cheers,

-- 
Francesc Alted

------------------------------------------------------------------------------
Crystal Reports - New Free Runtime and 30 Day Trial
Check out the new simplified licensing option that enables unlimited
royalty-free distribution of the report engine for externally facing 
server and web deployment.
http://p.sf.net/sfu/businessobjects
_______________________________________________
Pytables-users mailing list
Pytables-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/pytables-users

Reply via email to