[Numpy-discussion] For loop tips
kwgoodman at gmail.com
Tue Aug 29 14:27:34 CDT 2006
On 8/29/06, Tim Hochberg <tim.hochberg at ieee.org> wrote:
> Keith Goodman wrote:
> > I have a very long list that contains many repeated elements. The
> > elements of the list can be either all numbers, or all strings, or all
> > dates [datetime.date].
> > I want to convert the list into a matrix where each unique element of
> > the list is assigned a consecutive integer starting from zero.
> If what you want is that the first unique element get's zero, the second
> one, I don't think the code below will work in general since the dict
> does not preserve order. You might want to look at the results for the
> character case to see what I mean. If you're looking for something else,
> you'll need to elaborate a bit. Since list2index doesn't return
> anything, it's not entirely clear what the answer consists of. Just idx?
> Idx plus uL?
The output I wanted (in my mind, but unfortunately not in my previous
email) is idx and uL where uL corresponds to the zeros in idx,
uL corresponds to the ones in idx. etc.
I'd also like the uL's to be ordered (now I see that characters and
dates aren't ordered, ooops, thanks for telling me about that). Or
optionally ordered by a second list input which if present would be
used instead of the unique values of L.
Thank you all for the huge improvements to my code. I'll learn a lot
studying all of them.
More information about the Numpy-discussion