array from list of lists

Erin Sheldon erin.sheldon at gmail.com
Mon Nov 13 00:56:27 EST 2006


Hi all -

Thanks to everyone for the suggestions.
I think map(tuple, list) is probably the most compact,
but the list comprehension also works well.

Because map() is proably going to disappear someday, I'll
stick with the list comprehension.
  array( [tuple(row) for row in result], dtype=dtype)

That said, is there some compelling reason that the array
function doesn't support this operation?

Thanks again,
Erin

On 11/12/06, Robert Kern <robert.kern at gmail.com> wrote:
> Pierre GM wrote:
> > On Sunday 12 November 2006 20:10, Erin Sheldon wrote:
> >> Actually, there is a problem with that approach.  It first converts
> >> the entire array to a single type, by default a floating type.
> >
> > As A.M. Archibald suggested, you can use list comprehension:
> > N.array([(a,b,c,d,) for (a,b,c,d) in yourlist], dtype=yourdesc)
> >
> > or
> >
> > N.fromiter(((a,b,c,d) for (a,b,c,d,) in yourlist), dtype=yourdesc)
> >
> > Would you mind trying that, and let us know which one works best ? That could
> > be put on the wiki somewhere...
>
> N.array(map(tuple, yourlist), dtype=yourdesc)
>
> is probably the best option.
>
> --
> Robert Kern
>
> "I have come to believe that the whole world is an enigma, a harmless enigma
>  that is made terrible by our own mad attempt to interpret it as though it had
>  an underlying truth."
>   -- Umberto Eco
>
>
> -------------------------------------------------------------------------
> 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
> _______________________________________________
> Numpy-discussion mailing list
> Numpy-discussion at lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/numpy-discussion
>

-------------------------------------------------------------------------
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