A Wednesday 03 June 2009 18:44:41 Robert Ferrell escrigué:
> I'm trying to read rows from a table.  I wrote the table with a
> dictionary descriptor, which looks like {'label':
> tables.StringCol(16), 'x':tables. Float64Col(), 'y':tables.
> Float64Col()}
>
>       tbl = h5File.createTable(gp, tblName, tblDict, title='')
>
> If I read the whole table with tbl.read() I get an array of records,
> with the field names 'label', 'x', 'y', just as expected.
>
> However, I can't figure out how to read one row at a time and get a
> record array.  I've tried:
>
>       r = [row[:] for row in tbl]
>
> I get back a list with an item per row, but the rows are tuples, not
> record arrays.  How can I read the rows and get record arrays?

For getting pure NumPy void types, use `Row.fetch_all_fields()` instead.

>
> A second question.  Ultimately I want to read only rows with certain
> 'label' fields.  I have a set of labels, labelSet, and I want to get
> the rows with labels in that set:
>
>       r = [ row[:] for row in tbl if (row['label'] in labelSet)]
>
> Is there a better/faster way to select those rows?

Perhaps this?:

r = [ [row[l] for l in labelSet] for row in tbl]

-- 
Francesc Alted

------------------------------------------------------------------------------
OpenSolaris 2009.06 is a cutting edge operating system for enterprises 
looking to deploy the next generation of Solaris that includes the latest 
innovations from Sun and the OpenSource community. Download a copy and 
enjoy capabilities such as Networking, Storage and Virtualization. 
Go to: http://p.sf.net/sfu/opensolaris-get
_______________________________________________
Pytables-users mailing list
Pytables-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/pytables-users

Reply via email to