# Convert Any\[Any\[Any\[\]\]\] to 3D array?

**URL:** <https://discourse.julialang.org/t/convert-any-any-any-to-3d-array/16849>\
**Category:** New to Julia\
**Created:** [October 27, 2018, 7:49am UTC](https://discourse.julialang.org/t/convert-any-any-any-to-3d-array/16849 "2018-10-27T07:49:48Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![cenwangumass](https://avatars.discourse-cdn.com/v4/letter/c/bb73d2/32.png) [@cenwangumass](https://discourse.julialang.org/u/cenwangumass)\
**Post date:** [October 27, 2018, 7:49am UTC](https://discourse.julialang.org/t/convert-any-any-any-to-3d-array/16849/1 "2018-10-27T07:49:48Z")

</div>

I have some data that is of type Array{Float64, 3} and has the same shape as zeros(4, 25, 25). It is stored in JSON. But when I read it back from JSON, the data type becomes Any[Any[Any]]. What is the _idiomatic_ way of convert Any[Any[Any]] to Array{Float64, 3}? Thanks!

---

<div class="post-metadata">

**Author:** ![mauro3](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mauro3/32/292_2.png) [@mauro3](https://discourse.julialang.org/u/mauro3)\
**Post date:** [October 27, 2018, 8:08am UTC](https://discourse.julialang.org/t/convert-any-any-any-to-3d-array/16849/2 "2018-10-27T08:08:50Z")

</div>

Welcome! This works:

```julia
julia> a = [[[i+2*(j-1)+6*(k-1) for i=1:2] for j=1:3] for k=1:4]                                                                                                        
4-element Array{Array{Array{Int64,1},1},1}:                                                                                                                             
 [[1, 2], [3, 4], [5, 6]]                                                                                                                                               
 [[7, 8], [9, 10], [11, 12]]                                                                                                                                            
 [[13, 14], [15, 16], [17, 18]]                                                                                                                                         
 [[19, 20], [21, 22], [23, 24]]                                                                                                                                         

julia> reshape(hcat(hcat(a...)...), (4,3,2))                                                                                                                            
4×3×2 Array{Int64,3}:                                                                                                                                                   
[:, :, 1] =                                                                                                                                                             
 1 5 9                                                                                                                                                               
 2 6 10                                                                                                                                                               
 3 7 11                                                                                                                                                               
 4 8 12                                                                                                                                                               

[:, :, 2] =                                                                                                                                                             
 13 17 21                                                                                                                                                             
 14 18 22                                                                                                                                                             
 15 19 23                                                                                                                                                             
 16 20 24                                                                                                                                                             

julia> ans[:]'                                                                                                                                                          
1×24 LinearAlgebra.Adjoint{Int64,Array{Int64,1}}:                                                                                                                       
 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24                                                                                  

```

although I suspect there are more clever ways to do it. Note, the `hcat` seems to do the conversion as well.

PS: please quote your code: [PSA: how to quote code with backticks](https://discourse.julialang.org/t/psa-how-to-quote-code-with-backticks/7530)

---

<div class="post-metadata">

**Author:** ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Post date:** [October 27, 2018, 8:10am UTC](https://discourse.julialang.org/t/convert-any-any-any-to-3d-array/16849/3 "2018-10-27T08:10:04Z")

</div>

You can also just flatten twice:

```julia
# make an example
l1 = ones(2)
l2 = [l1, l1, l1]
l3 = [l2, l2, l2, l2]
# this is the code you want
collect(Iterators.flatten(Iterators.flatten(l3)))

```
