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.......

In reply to Sorting Index of An Array by neversaint

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.