I'm interested in sorting matrix columns in terms of values ββfrom two other vectors. As an example, suppose the matrix and vectors are as follows:
M = [ 1 2 3 4 5 6 ; 7 8 9 10 11 12 ; 13 14 15 16 17 18 ] v1 = [ 2 , 6 , 6 , 1 , 3 , 2 ] v2 = [ 3 , 1 , 2 , 7 , 9 , 1 ]
I want to sort the columns of A in terms of their respective values ββin v1 and v2 , with v1 precedence over v2 . Also, I am interested in sorting the matrix in place , because the matrices I work with are very large. Currently, my rude solution is as follows:
MM = [ v1' ; v2' ; M ] ;
which gives the desired result:
3x6 Array{Int64,2}: 4 6 1 5 2 3 10 12 7 11 8 9 16 18 13 17 14 15
Obviously, my approach is not ideal, as it requires computing and storing intermediate matrices. Is there a more efficient / elegant approach for sorting matrix columns through 2 other vectors? And can it be done in place to preserve memory?
I used to use sortperm to sort an array in terms of values ββstored in another vector. Is it possible to use sortperm with two vectors (and in place)?
sorting arrays matrix julia-lang
Landon
source share