[Numpy-discussion] For loop tips

Torgil Svensson torgil.svensson at gmail.com
Thu Aug 31 14:25:12 EDT 2006


def list2index(L):
    uL=sorted(set(L))
    idx=dict((y,x) for x,y in enumerate(uL))
    return uL,asmatrix(fromiter((idx[x] for x in L),dtype=int,count=len(L)))

adding the count will save you a little more time, and temporary
memory [see related thread].

//Torgil

On 8/29/06, Keith Goodman <kwgoodman at gmail.com> wrote:
> On 8/29/06, Torgil Svensson <torgil.svensson at gmail.com> wrote:
> > something like this?
> >
> > def list2index(L):
> >    uL=sorted(set(L))
> >    idx=dict((y,x) for x,y in enumerate(uL))
> >    return uL,asmatrix(fromiter((idx[x] for x in L),dtype=int))
>
> Wow. That's amazing. Thank you.
>
> -------------------------------------------------------------------------
> 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
>




More information about the NumPy-Discussion mailing list