Hi there, I'm new to Julia but have some experience with Matlab.
To sort each column of a matrix M ( r rows, c columns) I can write in Matlab:
[v i] = sort (M)m = 3 2
1 4
6 5
[v i] = sort(m)
v = 1 2
3 4
6 5
i = 2 1
1 2
3 3i = mapslices(sortperm, m, 1);
offset=repmat( (0:(c-1))'.*r ,r, 1); #'
v = m[offset+i];mapslices(x - > m[ x[:, ciom ], ciom], i, 1);
or do i need to do a for?
for ciom=1:c; v[:,ciom] =m [ i[:, ciom ], ciom] ; end
other ideas?Actually, see https://github.com/JuliaLang/julia/issues/16273
sortperm(A, dim)
mapslices(sortperm, A, dim);
or?
But then I still need the values of the sorted matrix.
How can I get these? (maybe sortperm!)
would be nearly the same as:or?mapslices(sortperm, A, dim);
No, I think sortperm(A, dim) would need to return an array of single-index indices (i.e. to be used with A[i]). I posted a sample implementation for 2d arrays in the issue linked above, which should suffice for your use.