[Numpy-discussion] query to array
Keith Goodman
kwgoodman@gmail....
Wed Jan 31 17:19:14 CST 2007
On 1/31/07, Tom Denniston <tom.denniston@alum.dartmouth.org> wrote:
> i would do something like the following. I don't have your odbc
> library so I mocked it up with a fake iterator called "it". This
> example would be for a two column result where the first is an int and
> the second a string. Note it creates a recarray which you can have
> match you database column names if you want to generalize the
> function. All you need to provide is the dtype equivalent to your
> query result layout.
>
> In [2]: import numpy
>
> In [3]: it = iter([(1,'String1'), (2, 'String2')])
>
> In [4]: dtype = numpy.dtype([('intvalue', int), ('stringcolumn', '|S20')])
>
> In [5]: numpy.fromiter(it, dtype)
> Out[5]:
> array([(1, 'String1'), (2, 'String2')],
> dtype=[('intvalue', '<i4'), ('stringcolumn', '|S20')])
All this fromiter and recarray is confusing to me. But I'd like to learn.
How would I hook all this up to a query?
More information about the Numpy-discussion
mailing list