julia> a = [[1:10] for i in 1:5]
5-element Array{Array{Int64,1},1}:
 [1,2,3,4,5,6,7,8,9,10]
 [1,2,3,4,5,6,7,8,9,10]
 [1,2,3,4,5,6,7,8,9,10]
 [1,2,3,4,5,6,7,8,9,10]
 [1,2,3,4,5,6,7,8,9,10]

julia> hcat(a...)
10x5 Array{Int64,2}:
  1   1   1   1   1
  2   2   2   2   2
  3   3   3   3   3
  4   4   4   4   4
  5   5   5   5   5
  6   6   6   6   6
  7   7   7   7   7
  8   8   8   8   8
  9   9   9   9   9
 10  10  10  10  10

kl. 20:01:59 UTC+1 onsdag 26. februar 2014 skrev Alex følgende:
>
> Hi together,
>
> It seems to be quite natural to try converting Vector{Vector{T}} into 
> Matrix{T} or vice versa. Is this conversion problematic in some way? What 
> would be an efficient way to achieve it?
>
> As a first attempt I would do
> y = [[i,i] for i=1:3]
>
> mat = Array(eltype(y[1]),length(y),length(y[1]))
>
> for i=1:length(y)
>         mat[i,:] = y[i]
> end
>
> to get the matrix. And
>
> v = vcat(Vector{eltype(mat[1,1])}[mat[i,:][:] for i=1:size(mat,1)])
>
> I am sure there are more elegant ways of doing this.
>
> Thanks!
>
> - Alex.
>
>

Reply via email to