Is there an external mapping function in Julia?

I am trying to build all possible combinations of four vectors (parameters in the model) that would give me a large nx4 matrix, and I could then run a simulation for each set (row) of parameters. In R, I would achieve this using expand.gridMathematica-style, I could use something like an external product with vcatand reduce the output with hcat.

Is there any analog function expand.gridof R or an external card function?

Toy example:

A = [1 2]
B = [3 4]

some magic

output = [1 3, 1 4, 2 3, 2 4]
+3
source share
2 answers

Using the Iterators package, it might look like this:

using Iterators
for p in product([1,2], [3,4])
    println(p)
end

println . collect, .

+3

, , .

julia> a=[1, 2];

julia> b=[3, 4];

julia> [[i, j] for j in b, i in a]
2x2 Array{Any,2}:
 [1,3]  [2,3]
 [1,4]  [2,4]

julia> [[i, j] for j in b, i in a][:]
4-element Array{Any,1}:
 [1,3]
 [1,4]
 [2,3]
 [2,4]
+1

All Articles