[SciPy-user] list of arrays
Trevis Crane
t_crane at mrl.uiuc.edu
Fri May 25 15:39:57 EDT 2007
> -----Original Message-----
> From: scipy-user-bounces at scipy.org
[mailto:scipy-user-bounces at scipy.org] On
> Behalf Of Robert Kern
> Sent: Friday, May 25, 2007 2:32 PM
> To: SciPy Users List
> Subject: Re: [SciPy-user] list of arrays
>
> Trevis Crane wrote:
> >> -----Original Message-----
> >> From: scipy-user-bounces at scipy.org
> > [mailto:scipy-user-bounces at scipy.org] On
> >> Behalf Of Ryan May
> >> Sent: Friday, May 25, 2007 1:57 PM
> >> To: SciPy Users List
> >> Subject: Re: [SciPy-user] list of arrays
> >>
> >> Trevis Crane wrote:
> >>> Hi,
> >>>
> >>> If I have a list of arrays, what's the best way of getting the
last
> >>> element of each array without using a for-loop?
> >>>
> >> [array[-1] for array in list]
> >
> > [Trevis Crane]
> >
> > I know I'm often dense, but I'm unsure how to implement this
suggestion.
> > Here's some code to clarify what I mean:
> >
> > from numpy import *
> > a = array([1,2,3])
> > b = array([4,5,6])
> > c = array([7,8,9])
> >
> > d = []
> > d.append(a)
> > d.append(b)
> > d.append(c)
> >
> > Now, d is a list containing three arrays, a,b and c. I assume you
> > suggest something like this:
> >
> > d[array[-1] for array in d]
> >
> > But this returns a syntax error. I'm sure I'm missing something but
not
> > sure what.
>
> Exactly this:
>
> e = [array[-1] for array in d]
[Trevis Crane]
Gotcha. Thanks.
>
> No more. No less.
>
> --
> 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
> _______________________________________________
> SciPy-user mailing list
> SciPy-user at scipy.org
> http://projects.scipy.org/mailman/listinfo/scipy-user
More information about the SciPy-User
mailing list