imantha
imantha

Reputation: 3838

Getting the shape of nested arrays in Julia

I am wondering whether there is a function that would compute the shape of nested arrays.

 multiArr = [[1,2,3,4],[5,6,7,8]]
 size(multiArr)
 #Out > (2,)

I am looking for the output (2,4)

I am aware that if you convert it to a matrix you could get this output,

 mat = reshape(hcat(multiArr...),size(multiArr)[1],size(multiArr[1])[1])
 size(mat)
 #Out > (2,4)

But wondering if there is a way to get the inner dimensions of nested arrays ?

Upvotes: 3

Views: 424

Answers (1)

Przemyslaw Szufel
Przemyslaw Szufel

Reputation: 42244

You can just broadcast size over inner arrays:

julia> size.(multiArr)
2-element Vector{Tuple{Int64}}:
 (4,)
 (4,)

You will get a Vector of sizes because of course each of those can be different.

Upvotes: 6

Related Questions