Dear Masters,
Suppose I have a SINGLE dimensional array, which always forms a 'matrix'. This array can always be seen as
m x n matrix. In this example 9x9 matrix:
@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 );
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:
@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
So for example the first 'row' of
@sim
contain this line:
1.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
If we sort that 'first row' of
@sim, it will give this 'first row' in
@index_ordered
0, 1, 3, 2, 5, 8, 4, 7, 6,
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.
---
neversaint and everlastingly indebted.......