At the place of vector permutation in Julia?

Is it possible to reorder the values ​​in the vector specified by the index list?

I have two arrays and I want to sort arr2 based on arr1 , which are both pre-allocated.

 indices = zeros(length(arr1)) sortperm!(indices, arr1) arr2[indices] <-- this returns a copy 
+5
source share
1 answer

permute! - your friend. Check the help with ?permute! in the REPL request.

In particular,

 permute!(arr2,indices) 

should be replaced by arr2 in OP. But, documents suggest on large vectors, it might be better to create a new copy.

+7
source

Source: https://habr.com/ru/post/1247989/


All Articles