On Thu, Jul 9, 2015 at 7:41 AM, Joachim Dahl <[email protected]> wrote:
> I am trying to construct an array of arrays involving list comprehension in
> Julia 0.4
>
> julia> [ [1,2]; [[i-1,i,i+1] for i=2:4] ]
> 5-element Array{Any,1}:
>  1
>  2
>   [1,2,3]
>   [2,3,4]
>   [3,4,5]

I never liked the hcat and vcat syntax but here's what you can do

julia> [Array[[1, 2]]; [[i - 1, i, i + 1] for i = 2:4]]
4-element Array{Array{T,N},1}:
[1,2]
[1,2,3]
[2,3,4]
[3,4,5]

You can probably add type Annotations to construct a tighter type ...

>
> where what I want is [ [1,2], [1,2,3], [2,3,4], [3,4,5] ].
>
> I suppose I have to use T[ ] notation now, and I've tried:
> julia> Array{Int,1}[ [1,2]; Array{Int,1}[[i-1,i,i+1] for i=2:4] ]
>
> and other variations without any luck.
>
> How would I construct such an array?

Reply via email to