def argsort(x, topn=None, reverse=False):
 x = np.asarray(x)
 if (topn is None):
  topn = x.size
 if (topn <= 0):
  return []
 if reverse:
  x = (- x)
 if ((topn >= x.size) or (not hasattr(np, 'argpartition'))):
  return np.argsort(x)[:topn]
 most_extreme = np.argpartition(x, topn)[:topn]
 return most_extreme.take(np.argsort(x.take(most_extreme)))

def argsort ( x , topn = None , reverse = False ) : x = np . asarray ( x ) if ( topn is None ) : topn = x . size if ( topn <= 0 ) : return [ ] if reverse : x = ( - x ) if ( ( topn >= x . size ) or ( not hasattr ( np , 'argpartition' ) ) ) : return np . argsort ( x ) [ : topn ] most_extreme = np . argpartition ( x , topn ) [ : topn ] return most_extreme . take ( np . argsort ( x . take ( most_extreme ) ) )
returns the indices that would sort an array .