# Summing a vector of vectors in a non-allocating way

**URL:** <https://discourse.julialang.org/t/summing-a-vector-of-vectors-in-a-non-allocating-way/72161>\
**Category:** Performance\
**Tags:** memory-allocation, arrays\
**Created:** [November 27, 2021, 12:34pm UTC](https://discourse.julialang.org/t/summing-a-vector-of-vectors-in-a-non-allocating-way/72161 "2021-11-27T12:34:07Z")\
**Posts on this page:** 1\
**Showing post:** 5

<div class="post-metadata">

**Author:** ![lmiq](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lmiq/32/18314_2.png) [@lmiq](https://discourse.julialang.org/u/lmiq)\
**Post date:** [November 27, 2021, 2:22pm UTC](https://discourse.julialang.org/t/summing-a-vector-of-vectors-in-a-non-allocating-way/72161/5 "2021-11-27T14:22:33Z")

</div>

In any case, be aware of this:

```julia
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
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/summing-a-vector-of-vectors-in-a-non-allocating-way/72161)._
