Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Julia: Transforming an Array of Arrays in a 2-dimensional Array

Tags:

I have an Array d that contains an Array of floats:

julia> d 99-element Array{Array{Float64,1},1}: ... 

I'm trying to convert it into a 2-dimensional Array, and I sucessfully achieved my goal with:

data = Array(Float64,length(d),length(d[1])) for i in 1:length(d)     for j in 1:length(d[1])         data[i,j] = d[i][j]     end end 

Is there a simpler way of doing this?

like image 773
prcastro Avatar asked Jul 02 '14 03:07

prcastro


People also ask

How do you create an array of arrays in Julia?

An Array in Julia can be created with the use of a pre-defined keyword Array() or by simply writing array elements within square brackets([]). There are different ways of creating different types of arrays.

How do you reshape in Julia?

Reshaping array dimensions in Julia | Array reshape() Method The reshape() is an inbuilt function in julia which is used to return an array with the same data as the specified array, but with different specified dimension sizes. Parameters: A: Specified array.

How do you make a matrix in Julia?

Julia provides a very simple notation to create matrices. A matrix can be created using the following notation: A = [1 2 3; 4 5 6]. Spaces separate entries in a row and semicolons separate rows. We can also get the size of a matrix using size(A).


1 Answers

hcat(d...) and vcat(d...) should do what you want.

like image 198
ivarne Avatar answered Oct 03 '22 18:10

ivarne