Literal expression for array of vectors

You can reshape a vector of vectors:

julia> m = [Int[i+10j] for i in 1:3, j in 1:5];

julia> vec(m) |> println
[[11], [12], [13], [21], [22], [23], [31], [32], [33], [41], [42], [43], [51], [52], [53]]

julia> reshape([[11], [12], [13], [21], [22], [23], [31], [32], [33], [41], [42], [43], [51], [52], [53]], 3, 5)
3×5 Matrix{Vector{Int64}}:
 [11]  [21]  [31]  [41]  [51]
 [12]  [22]  [32]  [42]  [52]
 [13]  [23]  [33]  [43]  [53]

Yes. The syntax goes to hvcat, and this unfortunately makes assembling block matrices easy, and matrices of arrays hard. The syntax I wrote above is Base.vect which is not a concatenation function.

It’s arguably a bug that println(m) produces something which doesn’t parse back to the same.

3 Likes