[Numpy-discussion] converting discrete data to unique integers

Alan G Isaac aisaac@american....
Wed Nov 4 14:21:03 CST 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)))

fwiw,
Alan Isaac



More information about the NumPy-Discussion mailing list