Skip to content

Instantly share code, notes, and snippets.

@vinaykudari
Created July 25, 2018 19:40
Show Gist options
  • Save vinaykudari/3c9ca9308a221bc2945bfd7d1cdbf2ab to your computer and use it in GitHub Desktop.
Save vinaykudari/3c9ca9308a221bc2945bfd7d1cdbf2ab to your computer and use it in GitHub Desktop.
Argsort
ages = np.random.randint(10,50,10)
heights = np.random.randint(120,210,10)
>> ages
[24 22 13 26 31 20 29 32 34 19]
>> heights
[146 141 166 191 169 203 149 135 170 152]
sorter = np.argsort(ages)
ages[sorter]
>> [13 19 20 22 24 26 29 31 32 34]
>>heights[sorter] #sorting heights according to ages.
[166 152 203 141 146 191 149 169 135 170]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment