I have two vectors, say, x=[1;1]
and y=[2;2]
I want to construct a vector whose element is a combination of these two, i.e. z=[[1,2],[1,2]]
What is the most efficient way to do that?
Just use zip
. By default, this will create a vector of tuples:
julia> z = collect(zip(x,y))
2-element Array{Tuple{Int64,Int64},1}:
(1,2)
(1,2)
Note that this is different than what you wanted, but it'll be much more efficient. If you really want an array of arrays, you can use a comprehension:
julia> [[a,b] for (a,b) in zip(x,y)]
2-element Array{Array{Int64,1},1}:
[1,2]
[1,2]