Is it possible to rearrange the values in a vector given a list of indices?
I have two arrays and I want to sort arr2
based on arr1
which are both preallocated.
indices = zeros(length(arr1))
sortperm!(indices, arr1)
arr2[indices] <-- this returns a copy
permute!
is your friend. Check the help with?permute!
on the REPL prompt.Specifically,
should permute in-place
arr2
in the OP. But, the docs suggest on large vectors it might be better to just create a new copy.