# Vector of vectors

**URL:** <https://discourse.julialang.org/t/vector-of-vectors/13748>\
**Category:** General Usage\
**Created:** [August 20, 2018, 5:34am UTC](https://discourse.julialang.org/t/vector-of-vectors/13748 "2018-08-20T05:34:50Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![microlifecc](https://avatars.discourse-cdn.com/v4/letter/m/ed655f/32.png) [@microlifecc](https://discourse.julialang.org/u/microlifecc)\
**Post date:** [August 20, 2018, 5:34am UTC](https://discourse.julialang.org/t/vector-of-vectors/13748/1 "2018-08-20T05:34:50Z")

</div>

Hi everyone!  
I am trying to resize the inner vectors but I am confused as to what I am doing wrong.  
`A = [Vector{Any}() for i in 1:6]`  
and then:

```julia
a, b, c, d = 3, 4, 5, 6
for tt = 1:6
    a+=1
    resize!(A[tt], a)
    for rr = 1:a
        b+=1
        resize!(A[tt][rr], b)
        for tt2 = 1:b
            resize!(A[tt][rr][tt2], b)
        end
    end
end

```

Error:

> UndefRefError: access to undefined reference Stacktrace: [1] getindex(::Array{Any,1}, ::Int64) at ./array.jl:549 [2] macro expansion at ./In[70]:7 [inlined] [3] anonymous at ./\<missing\>:?

Thanks!

---

<div class="post-metadata">

**Author:** ![fredrikekre](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/fredrikekre/32/1688_2.png) [@fredrikekre](https://discourse.julialang.org/u/fredrikekre)\
**Post date:** [August 20, 2018, 5:51am UTC](https://discourse.julialang.org/t/vector-of-vectors/13748/2 "2018-08-20T05:51:50Z")

</div>

Don’t post the same question on multiple forums without linking them to each other, [arrays - Resize Vectors Julia - Stack Overflow](https://stackoverflow.com/questions/51924323/resize-vectors-julia).

It is also helpful to make the example as [minimal as possible](https://stackoverflow.com/help/mcve). This has the benefit that you often realize yourself what is wrong.

Here is a smaller example that shows the same behaviour:

```julia
julia> A = [Vector{Any}(undef, 1)]
1-element Array{Array{Any,1},1}:
 [#undef]

julia> A[1][1]
ERROR: UndefRefError: access to undefined reference
Stacktrace:
[...]

```

which is what happens when you call `resize!(A[tt][rr], b)` in your code: The entry `A[tt][rr]` is not initialized to anything, so you can not extract it and resize it.

Here is one, minimal, modification,that I think does what you want:

```julia
A = [Vector{Any}() for i in 1:6]
a, b, c, d = 3, 4, 5, 6
for tt = 1:6
    a+=1
    resize!(A[tt], a)
    for rr = 1:a
        b+=1
        A[tt][rr] = Vector{Any}(undef, b) # instead of resize!(A[tt][rr], b)
        for tt2 = 1:b
            A[tt][rr][tt2] = Vector{Any}(undef, b) # instead of resize!(A[tt][rr][tt2], b)
        end
    end
end

```
