[Numpy-discussion] converting discrete data to unique integers

josef.pktd@gmai... josef.pktd@gmai...
Wed Nov 4 15:36:39 CST 2009


On Wed, Nov 4, 2009 at 3:57 PM, David Warde-Farley <dwf@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
set.

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

Josef


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


More information about the NumPy-Discussion mailing list