neversaint has asked for the wisdom of the Perl Monks concerning the following question:
The problem is how can we sort this SINGLE array into another SINGLE array, such that the index is sorted decreasingly according to similarity value in @sim. That it gives this array as an output:@sim = ( 1.0, 0.9, 0.3, 0.6, 0.3, 0.3, 0.2, 0.3, 0.3, 0.9, 1.0, 0.3, 0.5, 0.3, 0.1, 0.2, 0.3, 0.4, 0.3, 0.3, 1.0, 0.6, 0.3, 0.2, 0.2, 0.3, 0.4, 0.6, 0.6, 0.6, 1.0, 0.2, 0.2, 0.3, 0.4, 0.5, 0.3, 0.3, 0.3, 0.2, 1.0, 0.1, 0.3, 0.4, 0.5, 0.3, 0.2, 0.2, 0.2, 0.1, 1.0, 0.2, 0.3, 0.2, 0.1, 0.2, 0.2, 0.3, 0.3, 0.1, 1.0, 0.8, 0.6, 0.3, 0.3, 0.2, 0.4, 0.4, 0.3, 0.8, 1.0, 0.8, 0.3, 0.4, 0.4, 0.5, 0.5, 0.2, 0.6, 0.8, 1.0 );
So for example the first 'row' of @sim contain this line:@index_ordered = ( 0, 1, 3, 2, 5, 8, 4, 7, 6, 1, 0, 3, 8, 2, 4, 7, 5, 6, 2, 3, 8, 0, 1, 4, 5, 7, 6, 3, 0, 2, 1, 8, 7, 6, 4, 5, 4, 8, 7, 0, 1, 2, 6, 3, 5, 5, 0, 7, 2, 3, 1, 8, 6, 4, 6, 7, 8, 3, 4, 2, 1, 5, 0, 7, 8, 6, 3, 4, 1, 5, 2, 0, 8, 7, 6, 3, 4, 2, 1, 0, 5 ); # This is created manually
If we sort that 'first row' of @sim, it will give this 'first row' in @index_ordered1.0, 0.9, 0.3, 0.6, 0.3, 0.3, 0.2, 0.3,0.3, and the 'index' is: 0 1 2 3 4 5 6 7 8 #this index value is seen "as if" it is stored in one array, #and not the overall index in @sim
So every 'row' in @sim correspond to the 'row' in @index_ordered and sorted. Thus the 'dimension' of @sim and @index_ordered is the same.0, 1, 3, 2, 5, 8, 4, 7, 6,
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Sorting Index of An Array
by shmem (Chancellor) on May 14, 2007 at 10:16 UTC | |
by salva (Canon) on May 14, 2007 at 12:08 UTC | |
by shmem (Chancellor) on May 14, 2007 at 13:18 UTC | |
Re: Sorting Index of An Array
by salva (Canon) on May 14, 2007 at 11:25 UTC | |
by naikonta (Curate) on May 14, 2007 at 13:47 UTC | |
Re: Sorting Index of An Array
by BrowserUk (Patriarch) on May 14, 2007 at 10:04 UTC | |
Re: Sorting Index of An Array
by Anonymous Monk on Jul 15, 2008 at 11:43 UTC |