[SciPy-User] numpy.lexsort
Gabriele Brambilla
gb.gabrielebrambilla at gmail.com
Fri Aug 21 10:50:20 EDT 2015
Hi I want to order a numpy.array using lexsort.
>>> import numpy as np
>>> surnames = ['Hertz', 'Galilei', 'Hertz']
>>> names = ['Heinrich', 'Galilao', 'Gustav']
>>> ind = np.lexsort((names,surnames))
>>> ind
array([1, 2, 0])
But how can I have an array ordered according to this indexes?
I would do
surnames2 = surnames.copy()
for i, a in enumerate(ind):
surnames2[i] = surnames[a]
But I think there should be another way without writing the cycle by myself.
Thanks
GB
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.scipy.org/pipermail/scipy-user/attachments/20150821/df38ddf7/attachment.html>
More information about the SciPy-User
mailing list