[Numpy-discussion] converting discrete data to unique integers
Neil Crighton
neilcrighton@gmail....
Wed Nov 4 16:23:05 CST 2009
<josef.pktd <at> gmail.com> writes:
> > 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.
>
unique always sorts, even if it uses set. So I'm pretty sure
all(unique(A) == unique(B)) is guaranteed.
Neil
More information about the NumPy-Discussion
mailing list