Sorting two numpy arrays

Suppose you have two numpy arrays arr1 and arr2 and you want to sort them in such a way that one of them is sorted with the index used to sort the second array. Probably not clear at this point. So, let's just look at an example:

In [1]: arr1 = array([3,1,4,2])
In [2]: arr2 = array([5,3,1,6])
In [3]: ind = lexsort((arr1,arr2))
In [4]: print arr1[ind]
[4 1 3 2]
In [4]: print arr2[ind]
[1 3 5 6]

Doing this, we have sorted the two arrays using the sorting order of the second one. For using sorting order of first array, simply inverse them in lexsort(). Note: in this case, all you're trying to do is getting lexsort() to return the indices of the sorting. So, it doesn't matter what you put as a first array.

Comments

  1. It presents a great number of video games which are be} sure to offer you countless fun. Grand Fortune casino's welcome bonus is 코인카지노 a 400% match going a lot as} $4,000. Follow this link and discover more Red Dog Casino bonuses and promotions. To see the video games which are excluded from the wagering contribution please check the time period 17.2 and 17.three of our general terms and situations.

    ReplyDelete

Post a Comment

Popular Posts