Loop-Created Matrices in Julia

Say we have arrays u and v and a function f. We need a matrix F consisting of f (ui, vi) for all terms u and v. Attempt:

F = [ [f(ui,vi) for vi in v] for ui in u]

The result is an array of arrays (in the words of Julia, Array{Array{Int64,1},1})

How can I convert this to a two-dimensional array? ( Array{Int64,2})

+4
source share
1 answer

Instead of two nested concepts, just use one multidimensional understanding :

F = [f(ui,vi) for vi in v, ui in u]
+7
source

Source: https://habr.com/ru/post/1616881/


All Articles