Create matrix from two vectors

Hi!
I’m not sure which comprehension syntax you tried, but this one seems to work:

julia> f(x, y) = x + y
f (generic function with 1 method)

julia> a = [1, 2];

julia> b = [1, 2, 3];

julia> A = [f(a[i], b[j]) for i = 1:2, j = 1:3]
2×3 Matrix{Int64}:
 2  3  4
 3  4  5

Notice the subtle difference with that one:

julia> A = [f(a[i], b[j]) for i = 1:2 for j = 1:3]
6-element Vector{Int64}:
 2
 3
 4
 3
 4
 5
10 Likes