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))
On Wed, Nov 4, 2009 at 3:57 PM, David Warde-Farley 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.
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
On Wed, Nov 4, 2009 at 14:21, Alan G Isaac wrote:
> 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)
On 4-Nov-09, at 3:09 PM, David Warde-Farley wrote:
> But I wonder if there's a better way to do this. Anyone ever run into
> this problem before?
Obviously I find the answer right after I hit "send". unique(d,
return_inverse=True).
Sorry for the noise.
David
__
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
Hi,
Suppose I have an array 'd'
In [75]: d
Out[75]:
array(['parrot', 'parrot', 'dog', 'cat', 'parrot', 'dog', 'parrot',
'cat',
'dog', 'dog', 'dog', 'cat', 'cat', 'dog', 'cat', 'parrot',
'cat',
'cat', 'dog', 'parrot', 'parrot', 'parrot', 'cat', 'dog',
'parrot',
'dog',