[Numpy-discussion] 1.6.2 no more unique for rows

Charles R Harris charlesr.harris at gmail.com
Tue May 29 14:42:06 EDT 2012


On Mon, May 28, 2012 at 9:18 PM, <josef.pktd at gmail.com> wrote:

>
> https://github.com/numpy/numpy/commit/74b9f5eef8fac643bf9012dbb2ac6b4b19f46892
> broke return_inverse for structured arrays, because of the use of mergesort
>
> I'm using structured dtypes to get uniques and return_inverse by rows
>
> >>> groups = np.random.randint(0,4,size=(10,2))
> >>> groups_ = groups.view([('',groups.dtype)]*groups.shape[1]).flatten()
> >>> groups
> array([[0, 2],
>       [1, 2],
>       [1, 1],
>       [3, 1],
>       [3, 1],
>       [2, 1],
>       [1, 0],
>       [3, 3],
>       [3, 2],
>       [0, 0]])
> >>> groups_
> array([(0, 2), (1, 2), (1, 1), (3, 1), (3, 1), (2, 1), (1, 0), (3, 3),
>       (3, 2), (0, 0)],
>      dtype=[('f0', '<i4'), ('f1', '<i4')])
>
> >>> np.argsort(groups_)
> array([9, 0, 6, 2, 1, 5, 4, 3, 8, 7])
>
> >>> np.argsort(groups_, kind='mergesort')
> Traceback (most recent call last):
>  File "<stdin>", line 1, in <module>
>  File "C:\Python26\lib\site-packages\numpy\core\fromnumeric.py", line
> 679, in argsort
>    return argsort(axis, kind, order)
> TypeError: requested sort not available for type
>
> >>> uni, uni_idx, uni_inv = np.unique(groups_, return_index=True,
> return_inverse=True)
> >>> uni_inv
> array([1, 4, 3, 6, 6, 5, 2, 8, 7, 0])
>
> exception in numpy 1.6.2rc2 (as reported by Debian for statsmodels)
>
>
I've been putting of, um, planning to implement the different sort kinds
for object/structured arrays for a while, sounds like it needs to get done.

Chuck
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20120529/4cd90666/attachment.html>


More information about the NumPy-Discussion mailing list