Last active
August 29, 2015 13:56
-
-
Save acadien/9313820 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
from numpy import * | |
x = random.random([10,3]) | |
x[range(10), fabs(x-0.5).argsort()[:,0]] | |
#Break it down niao | |
x1 = fabs(x-0.5) # numbers closest to 0.5 will be closest to 0 now. | |
x2 = x1.argsort() # returns the indexes of each sorted *row*, numbers closest to 0 are first | |
x3 = x2[:,0] # give me just the index of the smallest number | |
x4 = x[range(10),x3] # index back into the original array using the row information you've gathered |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment