array from list of lists

Erin Sheldon erin.sheldon at gmail.com
Sun Nov 12 19:09:18 EST 2006


I have to not ammend my statement a bit:
  
DBI 2.0 actually returns a lists of tuples, which would
work.  It appears to just be pgdb, the postgres interface,
that is returning lists of lists.  Still, I need to
interact with this database.

Erin

On Sun, Nov 12, 2006 at 06:56:29PM -0500, Erin Sheldon wrote:
> Hi all-
> 
> I want to take the result from a database query,
> and create a numpy array with field names and types 
> corresponding to the returned columns.
> 
> The DBI 2.0 compliant interfaces return lists
> of lists. E.g.
> 
> 
> [[94137100072000193L, 94, 345.57215100000002, -0.83673208099999996],
>  [94137100072000368L, 94, 345.60217299999999, -0.83766954299999996],
>  ....
>  [94137100083000157L, 94, 347.21668099999999, -0.83572582399999995],
>  [94137100084000045L, 94, 347.45524799999998, -0.829750074]]
> 
> 
> But the only examples I have found for creating an inhomogeneous
> array with fields involves lists of tuples.  e.g.
> 
> >>> mydescriptor = {'names': ('gender','age','weight'), 'formats':('S1',
> >>> 'f4', 'f4')}
> >>> a = array([('M',64.0,75.0),('F',25.0,60.0)], dtype=mydescriptor)
> 
> Trying something like this with a list of lists results in
> the following error:
> 
> TypeError: expected a readable buffer object
> 
> Now I could create the array and run a loop, copying
> in, but this would be less efficient.  Is there a way
> to do this in one step?
> 
> Thanks,
> Erin
> 

-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642




More information about the NumPy-Discussion mailing list