# Proper way to concatenate higher-dimensional arrays?

**URL:** <https://discourse.julialang.org/t/proper-way-to-concatenate-higher-dimensional-arrays/50927>\
**Category:** New to Julia\
**Tags:** arrays\
**Created:** [November 29, 2020, 5:54am UTC](https://discourse.julialang.org/t/proper-way-to-concatenate-higher-dimensional-arrays/50927 "2020-11-29T05:54:46Z")\
**Posts on this page:** 4\
**Page:** 2

<div class="post-metadata">

**Author:** ![stillyslalom](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stillyslalom/32/45687_2.png) [@stillyslalom](https://discourse.julialang.org/u/stillyslalom)\
**Post date:** [November 30, 2020, 2:20am UTC](https://discourse.julialang.org/t/proper-way-to-concatenate-higher-dimensional-arrays/50927/21 "2020-11-30T02:20:40Z")

</div>

Sorry, my example is the same nested loop, just using a more compact syntax. Rewritten with your loop structure,

```julia
DatArr = [ElasticMatrix{Float64}(undef, 3, 0) for j = 1:Nj, k = 1:Nk]
for i in 1:5
	for j in 1:Nj
		for k in 1:Nk
			Nrand = rand(1:10)
			xyzVect = ElasticArray{Float64}(undef, 3, 0)
			for n in 1:Nrand
			   append!(xyzVect,rand(3))
			end
			append!(DatArr[j,k], xyzVect)
		end
	end    
end

```

---

<div class="post-metadata">

**Author:** ![CosmoProf](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cosmoprof/32/15516_2.png) [@CosmoProf](https://discourse.julialang.org/u/CosmoProf)\
**Post date:** [November 30, 2020, 2:30am UTC](https://discourse.julialang.org/t/proper-way-to-concatenate-higher-dimensional-arrays/50927/22 "2020-11-30T02:30:03Z")

</div>

I thought I tried that exact thing!!

The only difference seems to be in the definition line `DatArr = [ElasticMatrix...`.

Anyway, this seems to work, thank you!  
I will analyze and see what it produces, I’m optimistic…

---

<div class="post-metadata">

**Author:** ![stillyslalom](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stillyslalom/32/45687_2.png) [@stillyslalom](https://discourse.julialang.org/u/stillyslalom)\
**Post date:** [November 30, 2020, 2:36am UTC](https://discourse.julialang.org/t/proper-way-to-concatenate-higher-dimensional-arrays/50927/23 "2020-11-30T02:36:41Z")

</div>

The other difference is here:

```julia
append!(DatArr[j,k,:,:], xyzVect)

```

to

```julia
append!(DatArr[j,k], xyzVect)

```

---

<div class="post-metadata">

**Author:** ![CosmoProf](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cosmoprof/32/15516_2.png) [@CosmoProf](https://discourse.julialang.org/u/CosmoProf)\
**Post date:** [December 2, 2020, 12:49am UTC](https://discourse.julialang.org/t/proper-way-to-concatenate-higher-dimensional-arrays/50927/24 "2020-12-02T00:49:39Z")

</div>

Yes, stillyslalom, the method works.  
Thanks for the help!

[Previous page](https://discourse.julialang.org/t/proper-way-to-concatenate-higher-dimensional-arrays/50927.md?page=1)
