On 5/6/07, Jouni K. Sepp=E4nen <jks@...> wrote:
> Tommy Grav <tgrav@...> writes:
>
> > I would now like to plot a vs e for all the obj objects in nlist.
> > how do I do that? I tried
> >
> > plot(nlist[:].a,nlist[:].e,'ko')
>
> You have a list of objects that have attributes named a and e; these
> are not attributes of the list. Try
>
> plot([x.a for x in nlist], [x.e for x in nlist], 'ko')
Another idiom which I use a lot
a,e =3D zip(*[(o.a, o.e) for o in nlist])
or if I have a lot of attributes I want dumped into arrays
a,b,c,d =3D map(numpy.asarray, zip(*[(o.a, o.b, o.c, o.d) for o in data])=
)
JDH
|