[Numpy-discussion] converting discrete data to unique integers
robert.kern at gmail.com
Wed Nov 4 15:22:19 EST 2009
On Wed, Nov 4, 2009 at 14:21, Alan G Isaac <aisaac at american.edu> wrote:
> On 11/4/2009 3:09 PM, David Warde-Farley wrote:
>> I'd like to map every unique element (these could be strings, objects,
>> or already ints) to a unique integer between 0 and len(unique(d)) - 1.
> mymap = dict((k,v) for v,k in enumerate(set(a)))
I'd toss in a sorted() just to keep the mapping stable.
"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
More information about the NumPy-Discussion