[Numpy-discussion] converting discrete data to unique integers

josef.pktd at gmail.com josef.pktd at gmail.com
Wed Nov 4 16:36:39 EST 2009

On Wed, Nov 4, 2009 at 3:57 PM, David Warde-Farley <dwf at cs.toronto.edu> wrote:
> Thanks Alan and Robert, I probably should have mentioned that I was
> interested in obtaining the corresponding integer for each value in
> the array d, in which case the dictionary bit works but would require
> a further loop to expand.
> On 4-Nov-09, at 3:22 PM, Robert Kern wrote:
>> I'd toss in a sorted() just to keep the mapping stable.
> Good point. With the return_inverse solution, is unique() guaranteed
> to give back the same array of unique values in the same (presumably
> sorted) order? That is, for two arrays A and B which have elements
> only drawn from a set S, is all(unique(A) == unique(B)) guaranteed?
> The code is a quite clever and a bit hard to follow, but it *looks*
> like it will provide a stable mapping since it's using a sort.

I looked at it some time ago, and from what I remember, the sort
is done if return_inverse=True but for some codepath it uses

So, you would need to check which version includes the sort.


> David
> _______________________________________________
> NumPy-Discussion mailing list
> NumPy-Discussion at scipy.org
> http://mail.scipy.org/mailman/listinfo/numpy-discussion

More information about the NumPy-Discussion mailing list