sailx
sailx

Reputation: 164

array/list manipulation in Julia

I am unfamiliar with Julia notation, and coming from python.

In python, my code would look like this:

x = [0,1,2]
y = ([3,4, 5], [6,7,8])  # usually retuned by a function call

# then I stack the list:
z = [x, *y]

and get:

z = [[0, 1, 2], [3, 4, 5], [6, 7, 8]]

However, in julia, I am not sure how to use the * trick, I am using a cumbersome method where I defined all the variables:

x = [0,1,2]
y = ([3,4, 5], [6,7,8])  # usually retuned by a function call


z = x
z = hcat(z, y[1])
z = hcat(z, y[2])

What would be a more efficient way to write this down? Here this example is simple enough, but I am dealing with more xomplex data and doing the hcat like this feel wrond and is time consuming.

Upvotes: 4

Views: 189

Answers (1)

Przemyslaw Szufel
Przemyslaw Szufel

Reputation: 42214

In Julia you will use ... to unpack vector instead of * used in Python:

julia> [x, y...]
3-element Vector{Vector{Int64}}:
 [0, 1, 2]
 [3, 4, 5]
 [6, 7, 8]

Upvotes: 4

Related Questions