Quantcast
Channel: First steps - JuliaLang
Viewing all articles
Browse latest Browse all 2795

Explicit constructor for array of arrays?

$
0
0

I want to create an array of arrays explicitly. Initially I thought that this would work:

julia>  x = [ [1]  [1,2]
              []   [3,4,5] ]

but this does not work (I was expecting

2×2 Array{Any,2}:
 [1]    [1, 2]
 Any[]  [3, 4, 5]

of course).

Then I tried to use comas, semicolons, in different places, but I could not find any alternative that works. Is there one?

Just to contextualize: What I am facing is a didactic problem only. I am asking students to write a function which will deal with this array of arrays, and I want to provide that array as the input of the exercise. At this point I did not find any simpler way to initialize it than the somewhat cumbersome, for this purpose,

julia> x = Array{Any}(undef,2,2);

julia> x[1,1] = [1] ; x[1,2] = [1,2]; x[2,1] = []; x[2,2] = [3,4,5];

7 posts - 2 participants

Read full topic


Viewing all articles
Browse latest Browse all 2795

Latest Images

Trending Articles



Latest Images