# I feel like I am over complicating this - HDF5 saving array

**URL:** <https://discourse.julialang.org/t/i-feel-like-i-am-over-complicating-this-hdf5-saving-array/24284>\
**Category:** New to Julia\
**Created:** [May 16, 2019, 2:47pm UTC](https://discourse.julialang.org/t/i-feel-like-i-am-over-complicating-this-hdf5-saving-array/24284 "2019-05-16T14:47:51Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ahmed\_Salih](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ahmed_salih/32/206579_2.png) [@Ahmed\_Salih](https://discourse.julialang.org/u/Ahmed_Salih)\
**Post date:** [May 16, 2019, 2:47pm UTC](https://discourse.julialang.org/t/i-feel-like-i-am-over-complicating-this-hdf5-saving-array/24284/1 "2019-05-16T14:47:52Z")

</div>

Hello guys

I want to save an array of the following type;

```julia
Array{Array{Float32,2},1}

```

I have called it “B” and I want to save it in a hdf5 file. It gives me an error, with no method matching and I don’t know how to get past it. It works if I try to save only a part of B, ie. B[1], but does not work if I try to save the whole array directly. I am pretty sure I am misunderstanding something very simple, so I hope someone could push me in the right direction?

Kind regards

```julia
using HDF5

 B = Vector{Array{Float32,2}}(undef,3)
 B[1] = rand(3,3);
 B[2] = rand(3,3);
 B[3] = rand(3,3);

h5open("B.hdf5", "w") do file
    write(file, "B",B) # alternatively, say "@write file A"
    close(file)
end

```

---

<div class="post-metadata">

**Author:** ![Daneel](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/daneel/32/175_2.png) [@Daneel](https://discourse.julialang.org/u/Daneel)\
**Post date:** [May 16, 2019, 2:57pm UTC](https://discourse.julialang.org/t/i-feel-like-i-am-over-complicating-this-hdf5-saving-array/24284/2 "2019-05-16T14:57:45Z")

</div>

Is HDF5 a requirement? If not then you can use [JLD.jl](https://github.com/JuliaIO/JLD.jl) or [JLD2.jl](https://github.com/JuliaIO/JLD2.jl). I believe they both used different modified HDF5 formats.

---

<div class="post-metadata">

**Author:** ![Ahmed\_Salih](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ahmed_salih/32/206579_2.png) [@Ahmed\_Salih](https://discourse.julialang.org/u/Ahmed_Salih)\
**Post date:** [May 16, 2019, 3:03pm UTC](https://discourse.julialang.org/t/i-feel-like-i-am-over-complicating-this-hdf5-saving-array/24284/3 "2019-05-16T15:03:02Z")

</div>

I just thought that the hdf5.jl package was the best developed, so that is why I chose it. It seems like they use the same syntax, so I would still not know how to save my B array - could you help me out with that?

Kind regards

---

<div class="post-metadata">

**Author:** ![ggggggggg](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ggggggggg/32/265_2.png) [@ggggggggg](https://discourse.julialang.org/u/ggggggggg)\
**Post date:** [May 16, 2019, 3:13pm UTC](https://discourse.julialang.org/t/i-feel-like-i-am-over-complicating-this-hdf5-saving-array/24284/4 "2019-05-16T15:13:07Z")

</div>

HDF5 will save arrays of numeric types (eg `Int64`, `Float64`, etc) but it won’t save more complicated types by default. You can either save the vector elements yourself like

```julia
 B = Vector{Array{Float32,2}}(undef,3)
 B[1] = rand(3,3);
 B[2] = rand(3,3);
 B[3] = rand(3,3);

h5open("B.hdf5", "w") do file
    file["B1"] = B[1]
    file["B2"] = B[2]
    file["B3"] = B[3]
end

```

Or use a 3d array instead of a vector of 2d arrays like

```julia
C = zeros(3,3,3)
C[1,:,:] = rand(3,3);
C[2,:,:] = rand(3,3);
C[3,:,:] = rand(3,3);
h5open("C.hdf5", "w") do file
    file["C"]=C
end

```

I would recommend HDF5 over JLD if you want your data to be accesible to non-julia users, and if you don’t have super complicated data structures.
