[Numpy-discussion] converting discrete data to unique integers

Alan G Isaac aisaac at american.edu
Wed Nov 4 15:21:03 EST 2009

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)))

Alan Isaac

More information about the NumPy-Discussion mailing list