# Creating multidimensional arrays

**URL:** <https://discourse.julialang.org/t/creating-multidimensional-arrays/85630>\
**Category:** New to Julia\
**Tags:** arrays\
**Created:** [August 11, 2022, 5:05pm UTC](https://discourse.julialang.org/t/creating-multidimensional-arrays/85630 "2022-08-11T17:05:34Z")\
**Posts on this page:** 1\
**Showing post:** 4

<div class="post-metadata">

**Author:** ![jacobusmmsmit](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jacobusmmsmit/32/217669_2.png) [@jacobusmmsmit](https://discourse.julialang.org/u/jacobusmmsmit)\
**Post date:** [August 11, 2022, 5:32pm UTC](https://discourse.julialang.org/t/creating-multidimensional-arrays/85630/4 "2022-08-11T17:32:45Z")

</div>

Be very careful when using `repeat`, it only creates one array and copies the same one to multiple locations. Editing one of the values will affect them _all_.

Go far back enough in my activity and you’ll find that this caused a huge bug in my code.

Edit: It’s a nuanced case, I think it’s fine here because the elements of the array are bitstypes, but arrays of arrays will cause issues when used with repeat:

> [@Summing a vector of vectors in a non-allocating way](https://discourse.julialang.org/t/summing-a-vector-of-vectors-in-a-non-allocating-way/72161/5):
>
> In any case, be aware of this: julia\> x = repeat([[0,0]],3) 3-element Vector{Vector{Int64}}: [0, 0] [0, 0] [0, 0] julia\> x[1][1] = 1 1 julia\> x 3-element Vector{Vector{Int64}}: [1, 0] [1, 0] [1, 0] use a comprehension probably: julia\> x = [[0,0] for \_ in 1:3 ] 3-element Vector{Vector{Int64}}: [0, 0] [0, 0] [0, 0] julia\> x[1][1] = 1 1 julia\> x 3-element Vector{Vector{Int64}}: [1, 0] [0, 0] [0, 0]

---

_[View the full topic](https://discourse.julialang.org/t/creating-multidimensional-arrays/85630)._
