From: Tim H. <tim...@ie...> - 2006-11-13 04:01:42
|
Erin Sheldon wrote: > On 11/12/06, Tim Hochberg <tim...@ie...> wrote: > >> I haven't been following this too closely, but if you need to transpose >> your data without converting all to one type, I can think of a couple of >> different approaches: >> >> 1. zip(*yourlist) >> 2. numpy.transpose(numpy.array(yourlist, dtype=object) >> >> I haven't tested them though (particularly the second one), so caveat >> emptor, etc, etc. >> > > Its not that I want to transpose data. > > I'm trying to convert the output of a pgdb postgres query into > an array with fields and types corresponding to the columns > I have selected. The problem is pgdb does not return a list > of tuples as it should according to DB 2.0, but instead > a list of lists. So numpy.array(lol, dtype=) fails, and so will your > solution #2. In that case, I suggest just using a list comprehension or map, [tuple(x) for x in lol] for example. > I don't want to copy the data more than once > obviously, so I'm looking for a way to call array() with a lists > of lists. > It's probably pointless to worry about his. You are already allocating 5*N python objects (all those Python floats and integers as well as the lists themselves). I believe the list comprehension above is only going to allocate an additional N objects (the new tuples). Admittedly, the objects aren't all the same size, but in this case they are close enough that I doubt it'll matter. -tim |