public static int [ ] Argsort ( final float [ ] array , final boolean ascending ) { Integer [ ] indexes = new Integer [ array . length ] ; for ( int i = 0 ; i < indexes . length ; i ++ ) { indexes [ i ] = i ; } Arrays . sort ( indexes , new Comparator < Integer > ( ) { @ Override public int compare ( final Integer i1 , final Integer i2 ) { return ( ascending ? 1 : - 1 ) * Float . compare ( array [ i1 ] , array [ i2 ] ) ; } } ) ; return asArray ( indexes ) ; }
Returns the indices that would sort an array .