# Array of arrays to a single nxn dimensional array

**URL:** <https://discourse.julialang.org/t/array-of-arrays-to-a-single-nxn-dimensional-array/15753>\
**Category:** New to Julia\
**Created:** [October 1, 2018, 6:21pm UTC](https://discourse.julialang.org/t/array-of-arrays-to-a-single-nxn-dimensional-array/15753 "2018-10-01T18:21:12Z")\
**Posts on this page:** 1\
**Showing post:** 7

<div class="post-metadata">

**Author:** ![rdeits](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rdeits/32/286_2.png) [@rdeits](https://discourse.julialang.org/u/rdeits)\
**Post date:** [October 2, 2018, 12:05pm UTC](https://discourse.julialang.org/t/array-of-arrays-to-a-single-nxn-dimensional-array/15753/7 "2018-10-02T12:05:09Z")

</div>

I suspect `foldl`’s guaranteed associativity means that it has to allocate a new matrix for the result of `hcat` for every single column. That’s unnecessary and wasteful, but it’s required by the guarantee that foldl makes. Since `reduce` makes no such guarantee, it is free to take a faster path and avoid the extra copies.

Edit: see [Problem with cat() - #9 by nalimilan](https://discourse.julialang.org/t/problem-with-cat/15750/9)

---

_[View the full topic](https://discourse.julialang.org/t/array-of-arrays-to-a-single-nxn-dimensional-array/15753)._
