Suppose our darling A
looks like
60.0 3.0
675.0 3.0
1050.0 4.0
0.0 0.0
I want to loop through the rows in decreasing order of the first column. Something like...
for r in sorted(A, by=A[1,], reverse=True) {
writeln(r);
}
I'd like
1050.0 4.0
675.0 3.0
60.0 3.0
0.0 0.0
The Sort documentation does not address 2D arrays.
As you have observed, the Sort module currently only supports 1D arrays.
As a work-around to this, you could write a
sort()
wrapper that restructures your data into an array of arrays and sort on that, if you're willing to accept a penalty in performance, due to creating a temp-array and iterating over it twice.An example of this: