A Wednesday 23 July 2008, Kevin Christman escrigué:
> I have a Pytables table called Data. I do kExp =
> Data.readWhere('(MotorCompany == "Reliance")') to pick out some of
> the data. Now the type(kExp) is numpy.ndarray, and kExp.shape is
> (500,). but the type(kExp[0]) is numpy.void, and kExp[0] looks like a
> list.
This is because the returned object ``kExp`` is a NumPy recarray.
>
> I would like kExp to be a 2dimensional numpy array so that I can
> pick out columns like kExp[:,0]. I've tried doing kExp =
> numpy.array(kExp) but that still doesn't turn kExp to be a
> 2dimensional numpy array.
You missed to tell us which schema has your table. Here it is, however,
a small example for doing something similar:
In [20]: t = numpy.ones(10, dtype='i4,i4')
In [21]: t
Out[21]:
array([(1, 1), (1, 1), (1, 1), (1, 1), (1, 1), (1, 1), (1, 1), (1, 1),
(1, 1), (1, 1)],
dtype=[('f0', '<i4'), ('f1', '<i4')])
In [22]: c = numpy.empty((2,10), 'i4')
In [23]: c
Out[23]:
array([[1209490840, 1209490840, 2710825, 3, 1009197100,
690435177, 6, 6, 6,
6],
[ 6, 6, 6, 0, 0,
9, 0, 0, 12,
0]])
In [24]: c[0] = t['f0']
In [25]: c[1] = t['f1']
In [26]: c[0]
Out[26]: array([1, 1, 1, 1, 1, 1, 1, 1, 1, 1])
In [27]: c[1]
Out[27]: array([1, 1, 1, 1, 1, 1, 1, 1, 1, 1])
In [28]: c
Out[28]:
array([[1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
[1, 1, 1, 1, 1, 1, 1, 1, 1, 1]])
More examples of recarray usage can be found at:
http://www.scipy.org/Numpy_Example_List_With_Doc
A deep read of the above document is extremely useful to take the most
out of NumPy (and recarray in particular) objects.
HTH,

Francesc Alted
Freelance developer
Tel +34964282249
