I am new to Julia (some experience with Python). The main reason I am starting to use Julia is better performance for large scale data processing.
I want to get differences of values (int) of all possible combinations in two arrays.
Say I have two arrays.
a = [5,4]
b = [2,1,3]
Then I want to have differences of all combinations like a[1] - b[1], a[1] - b[2] ..... a[3] - b[1], a[3] - b[2]
The result will be 3 x2 array [3 2; 4 3; 2 1]
Then something I came up is
a = [5,4]
b = [2,1,3]
diff_matrix = zeros(Int8, size(b)[1], size(a)[1])
for ia in eachindex(a)
for ib in eachindex(b)
diff_matrix[ib,ia]= a[ia] - b[ib]
end
end
println(diff_matrix)
It works but it uses iteration inside of iteration and I assume the performance will not be great. In real application, length of array will be long (like a few hundreds), and this process needs to be done for millions of combinations of arrays.
Is there any better (better performance, simpler code) approach for this task ?