[Numpy-discussion] Adding an axis argument to numpy.unique

Joe Kington joferkington@gmail....
Sun Aug 18 18:14:55 CDT 2013


Hi everyone,

I've recently put together a pull request that adds an `axis` kwarg to
`numpy.unique` so that `unique`can easily be used to find unique
rows/columns/sub-arrays/etc of a larger array.

https://github.com/numpy/numpy/pull/3584

Currently, this works as a warpper around `unique`. If `axis` is specified,
it reshapes the input to a 2D contiguous array, views each row as a single
item, then passes it on to `unique`.  For int and string dtypes, each row
is viewed as a void dtype and therefore bitwise-equality is used for
comparisons.  For all other dtypes, the each row is viewed as a structured
array.

The current implementation has two main drawbacks:

   1. For anything other than ints and strings, it's relatively slow.
   2. It doesn't work with object arrays of any sort.

I'd appreciate any thoughts/feedback folks might have on both the general
idea and this specific implementation.  It think it's a worthwhile
addition, but I'm biased.

Thanks!
-Joe
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.scipy.org/pipermail/numpy-discussion/attachments/20130818/7d888994/attachment.html 


More information about the NumPy-Discussion mailing list