Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Best way to convert Array{Array{Float64},1} to Array{Float64,2} and vise versa

Tags:

arrays

julia

Consider an array of arrays

julia> a
2-element Array{Array{Float64,1},1}:
 [1.0, 2.0, 3.0]
 [4.0, 5.0, 6.0]

I want to convert a into an Array{Float64,2}

2×3 Array{Float64,2}:
 1.0  2.0  3.0
 4.0  5.0  6.0

like so.

I found out that one solution hcat(a...)'

julia> hcat(a...)'
2×3 Adjoint{Float64,Array{Float64,2}}:
 1.0  2.0  3.0
 4.0  5.0  6.0

Here type is Adjoint{Float64,Array{Float64,2}}. But for my problem, I need only Array{Float64,2}. And after some computations, I need to convert it back into array of arrays. I am wondering, what should be the best way to do this.

Thanks in advance.

like image 460
Maqsood Mubarak Rajput Avatar asked Dec 07 '25 14:12

Maqsood Mubarak Rajput


1 Answers

Are you looking for vcat(a'...) It does what you want.

like image 102
Oscar Smith Avatar answered Dec 09 '25 02:12

Oscar Smith



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!