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
A Vector in Julia can be created with the use of a pre-defined keyword Vector() or by simply writing Vector elements within square brackets([]). There are different ways of creating Vector. vector_name = [value1, value2, value3,..] or vector_name = Vector{Datatype}([value1, value2, value3,..])
We should have dot(x::RowVector, y::RowVector) = dot(transpose(x), transpose(y)) (see mailing list). Mathematically, an inner product on a vector space induces an... But if we define dot(a,b) = a'*b one would expect to get back a matrix (the outer product) when a and b are row vectors.
The magnitude of a vector comes from the distance formula applied to a line segment, and is ∥→v∥=√x2+y2 ‖ v → ‖ = x 2 + y 2 . A vector and its unit vector.
permute!
is your friend. Check the help with ?permute!
on the REPL prompt.
Specifically,
permute!(arr2,indices)
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With