[Numpy-discussion] 1.6.2 no more unique for rows
josef.pktd at gmail.com
josef.pktd at gmail.com
Mon May 28 23:18:44 EDT 2012
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)
Josef
More information about the NumPy-Discussion
mailing list