Ordering Of Matrix Columns

You can also sort the columns and re-assemble:

julia> A = randn(2,5);

julia> reduce(hcat, sort(eachcol(A); by=norm))
2×5 Matrix{Float64}:
 -0.111708  -1.31249   -1.49302    1.11223   0.730328
  0.684414   0.589954  -0.115788  -1.068    -1.93679

julia> ans == A[:, sortperm(norm.(eachcol(A)))]
true

Edit: or better, use sortslices which takes the same keyword:

julia> sortslices(A, dims=2, by=norm)
2×5 Matrix{Float64}:
 -0.111708  -1.31249   -1.49302    1.11223   0.730328
  0.684414   0.589954  -0.115788  -1.068    -1.93679
4 Likes