[Numpy-discussion] stable sort on a recarray ?

butterw at gmail.com butterw at gmail.com
Mon Mar 28 15:34:19 EDT 2011

What is the recommended way to perform a stable sort on a recarray /  
structured array ?

In the following example, I want to sort on name, while retaining the  
existing order in the case of equal values:
values = [('a', 1), ('a', 0), ('b', 2)]
dtype = [('name', 'S10'), ('val', 'i4')]
>>> a = np.array(values, dtype=dtype)
array([('a', 1), ('a', 0), ('b', 2)],
dtype=[('name', '|S10'), ('val', '<i4')])
>>> np.sort(a, order='name')
array([('a', 0), ('a', 1), ('b', 2)],
dtype=[('name', '|S10'), ('val', '<i4')])
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20110328/af3bedac/attachment.html>

More information about the NumPy-Discussion mailing list