Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Converting Julia nested list to multidimensional array

Tags:

julia

Given a Julia list of lists:

data = [[1,2],[4,5]]

which has type Vector{Int64}, how can I convert this to a 2D data type (e.g. 2×2 Matrix{Int64}) so that I can index it like data[:,2]? I tried hcat or vcat but couldn't get the result that I wanted. Thanks in advance!

like image 465
RvdV Avatar asked May 07 '26 06:05

RvdV


1 Answers

You can do:

julia> reduce(hcat, data)
2×2 Matrix{Int64}:
 1  4
 2  5
like image 80
Nils Gudat Avatar answered May 11 '26 11:05

Nils Gudat