[Numpy-discussion] unique 2d arrays

Gökhan Sever gokhansever@gmail....
Tue Sep 21 12:55:12 CDT 2010


On Tue, Sep 21, 2010 at 12:43 PM, <josef.pktd@gmail.com> wrote:

> I'm a bit surprised, I think np.unique does some extra work to
> maintain the order.
> The tolist() might not be necessary if you iterate over rows.
>

Testing again with a smaller k array and more repeats

I[25]: k = np.array((a.tolist()*5000))

I[27]: %timeit -r 100 np.array(list(set(tuple(i) for i in k.tolist())))
10 loops, best of 100: 31.3 ms per loop

I[28]: %timeit -r 100 np.array(list(set(tuple(i) for i in k)))
10 loops, best of 100: 55.4 ms per loop

I[30]: %timeit -r 100
np.unique(k.view([('',k.dtype)]*k.shape[1])).view(k.dtype).reshape(-1,k.shape[1])
10 loops, best of 100: 60.5 ms per loop

.tolist version is faster. Can you also verify this?



-- 
Gökhan
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.scipy.org/pipermail/numpy-discussion/attachments/20100921/063e9183/attachment.html 


More information about the NumPy-Discussion mailing list