# Vector re-size

**URL:** https://discourse.julialang.org/t/vector-re-size/13733
**Category:** General Usage
**Created:** [August 19, 2018, 9:27pm UTC](https://discourse.julialang.org/t/vector-re-size/13733 "2018-08-19T21:27:39Z")
**Posts on this page:** 10
**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 19, 2018, 9:27pm UTC](https://discourse.julialang.org/t/vector-re-size/13733/1 "2018-08-19T21:27:39Z")

</div>

So I have two vector of vectors like:

> matchings\_vec = Vector{Vector{Vector{Vector{Any}}}}(num\_tilt1)  
> Minfoall\_vec = Vector{Vector{Vector{Vector{Vector{Vector{Float64}}}}}}(num\_tilt1)

I defined it as:

```julia
matchings_vec = [Vector{Any} for i in 1:num_tilt1]
Minfoall_vec = [Vector{Float64} for i in 1:num_tilt1]

```

Then I am trying to resize the inner vectors like:

```julia
for tt = 1:num_tilt1
    t_tt = t[tt]
    if t_tt == 1
        num_rot1 = 1
    else
        num_rot1 = round(Int, num_rot_t2 * t_tt/2)
        if rem.(num_rot1, 2) == 1.0
            num_rot1 += 1
        end
        num_rot1 /= 2
    end
    resize!(matchings_vec[tt], num_rot1)
    resize!(Minfoall_vec[tt], num_rot1)
    for rr = 1:num_rot1
        resize!(matchings_vec[tt][rr], num_tilt2)
        resize!(Minfoall_vec[tt][rr], num_tilt2)
        for tt2 = 1:num_tilt2
            t_im2 = t[tt2]
            if t_im2 == 1
                num_rot1_2 = 1
            else
                num_rot1_2 = round(Int, num_rot_t2 * t_im2/2)
                if rem.(num_rot1_2, 2) == 1.0
                    num_rot1_2 += 1
                end
                num_rot1_2 /= 2
            end
            resize!(matchings_vec[tt][rr][tt2], num_rot1_2)
            resize!(Minfoall_vec[tt][rr][tt2], num_rot1_2)
        end
    end
end

```

I am getting this error:

> MethodError: no method matching resize!(::Type{Array{Any,1}}, ::Int64)  
> Closest candidates are:  
> resize!(::Array{T,1} where T, ::Integer) at array.jl:767  
> resize!(::BitArray{1}, ::Integer) at bitarray.jl:825  
> resize!(::Gtk.GtkWindow, ::Integer, ::Integer) at /home/subhankar/julia/JuliaPro-0.6.4.1/JuliaPro/pkgs-0.6.4.1/v0.6/Gtk/src/windows.jl:18
> 
> Stacktrace:  
> [1] macro expansion at ./In[32]:12 [inlined]  
> [2] anonymous at ./:?

Can you suggest what I am doing wrong? Thanks!

---

<div class="post-metadata">

### Author: ![greg\_plowman](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/greg_plowman/32/8100_2.png) [@greg\_plowman](https://discourse.julialang.org/u/greg_plowman)
#### Post date: [August 19, 2018, 9:41pm UTC](https://discourse.julialang.org/t/vector-re-size/13733/2 "2018-08-19T21:41:10Z")

</div>

```julia
matchings_vec = [Vector{Any} for i in 1:num_tilt1]
Minfoall_vec = [Vector{Float64} for i in 1:num_tilt1]

```

These are defining vectors of types not instances.

---

<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 19, 2018, 9:55pm UTC](https://discourse.julialang.org/t/vector-re-size/13733/3 "2018-08-19T21:55:22Z")

</div>

Hi @greg_plowman. Thanks for the reply.  
Can you please suggest what I should do?  
Thanks!

---

<div class="post-metadata">

### Author: ![Nosferican](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nosferican/32/9275_2.png) [@Nosferican](https://discourse.julialang.org/u/Nosferican)
#### Post date: [August 19, 2018, 10:51pm UTC](https://discourse.julialang.org/t/vector-re-size/13733/4 "2018-08-19T22:51:16Z")

</div>

Could you post a minimal complete verifiable example and what you would like to obtain?

---

<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 19, 2018, 11:01pm UTC](https://discourse.julialang.org/t/vector-re-size/13733/5 "2018-08-19T23:01:56Z")

</div>

Hi @Nosferican! Thanks for the help.

So basically I have found features in img1 and stored them in a vector of vectors **keys\_all1** indexed by tt and rr. Now I need to match them with the keypoints in img2 stored in **keys\_all2** indexed by tt2 and rr2. So I am looping over each of the values of tt, rr, tt2 and rr2 and then comparing the keypoints and storing them in matchings\_vec.  
[Here’s](https://github.com/SubhankarGhosh/Affine-SIFT-Julia/blob/master/featureComputationAndComparison.ipynb) my work till date.

Thanks!

---

<div class="post-metadata">

### Author: ![greg\_plowman](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/greg_plowman/32/8100_2.png) [@greg\_plowman](https://discourse.julialang.org/u/greg_plowman)
#### Post date: [August 19, 2018, 11:45pm UTC](https://discourse.julialang.org/t/vector-re-size/13733/6 "2018-08-19T23:45:22Z")

</div>

> [@greg\_plowman](#):
>
> ```julia
> matchings_vec = [Vector{Any} for i in 1:num_tilt1]
> Minfoall_vec = [Vector{Float64} for i in 1:num_tilt1]
> 
> ```
> 
> These are defining vectors of types not instances.

Try this at the REPL:

```julia
d = Vector{Any}
typeof(d)

```

versus:

```julia
v = Vector{Any}()
typeof(v)

```

---

<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, 2:57am UTC](https://discourse.julialang.org/t/vector-re-size/13733/7 "2018-08-20T02:57:59Z")

</div>

> [@greg\_plowman](#):
>
> v = Vector{Any}() typeof(v)

Hi @greg_plowman. Thanks again!  
So I edited my code like this:

```julia
matchings_vec = [Vector{Any}() for i in 1:num_tilt1]
Minfoall_vec = [Vector{Any}() for i in 1:num_tilt1]

```

And to create the internal vector structure like this:

```julia
for tt = 1:num_tilt1
    t_tt = t[tt] #; t1 = t_tt; t2 = 1;
    if t_tt == 1
        num_rot1 = 1
    else
        num_rot1 = round(Int, num_rot_t2 * t_tt/2)
        if rem.(num_rot1, 2) == 1.0
            num_rot1 += 1
        end
        num_rot1 /= 2
    end
    #resize!(matchings_vec[tt], num_rot1)
    matchings_vec[tt] = Vector{Any}(num_rot1)
    #resize!(Minfoall_vec[tt], num_rot1)
    Minfoall_vec[tt] = Vector{Any}(num_rot1)
    for rr = 1:num_rot1
        #resize!(matchings_vec[tt][rr], num_tilt2)
        matchings_vec[tt][rr] = Vector{Any}(num_tilt2)
        #resize!(Minfoall_vec[tt][rr], num_tilt2)
        Minfoall_vec[tt][rr] = Vector{Any}(num_tilt2)
        for tt2 = 1:num_tilt2
            t_im2 = t[tt2]
            #t_im2_1 = t_im2; t_im2_2 = 1;
            if t_im2 == 1
                num_rot1_2 = 1
            else
                num_rot1_2 = round(Int, num_rot_t2 * t_im2/2)
                if rem.(num_rot1_2, 2) == 1.0
                    num_rot1_2 += 1
                end
                num_rot1_2 /= 2
            end
            #resize!(matchings_vec[tt][rr][tt2], num_rot1_2)
            matchings_vec[tt][rr][tt2] = Vector{Any}(num_rot1_2)
            #resize!(Minfoall_vec[tt][rr][tt2], num_rot1_2)
            Minfoall_vec[tt][rr][tt2] = Vector{Any}(num_rot1_2)
        end
    end
end

```

I am getting this error:

> MethodError: Cannot `convert` an object of type Float64 to an object of type Array{Any,1} This may have arisen from a call to the constructor Array{Any,1}(…), since type constructors fall back to convert methods. Stacktrace: [1] Array{Any,1}(::Float64) at ./sysimg.jl:77 [2] macro expansion at ./In[32]:34 [inlined] [3] anonymous at ./\<missing\>:?

Any suggestions please?

---

<div class="post-metadata">

### Author: ![greg\_plowman](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/greg_plowman/32/8100_2.png) [@greg\_plowman](https://discourse.julialang.org/u/greg_plowman)
#### Post date: [August 20, 2018, 3:20am UTC](https://discourse.julialang.org/t/vector-re-size/13733/8 "2018-08-20T03:20:32Z")

</div>

```julia
Vector{Any}(2)

```

versus

```julia
Vector{Any}(2.0)

```

If you put your code into a function, Julia will probably report the line number where the error occurs, and then you can see (or guess) what the problem is.

---

<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, 3:32am UTC](https://discourse.julialang.org/t/vector-re-size/13733/9 "2018-08-20T03:32:25Z")

</div>

Thanks @greg_plowman  
That works.  
Also do you think I should use:  
`resize!(Minfoall_vec[tt][rr][tt2], num_rot1_2)`  
or  
`Minfoall_vec[tt][rr][tt2] = Vector{Any}(num_rot1_2)`

---

<div class="post-metadata">

### Author: ![appcypher](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/appcypher/32/1917_2.png) [@appcypher](https://discourse.julialang.org/u/appcypher)
#### Post date: [August 20, 2018, 7:36am UTC](https://discourse.julialang.org/t/vector-re-size/13733/10 "2018-08-20T07:36:43Z")

</div>

> [@microlifecc](#):
>
> matchings\_vec = [Vector{Any} for i in 1:num\_tilt1] Minfoall\_vec = [Vector{Float64} for i in 1:num\_tilt1]

This won’t give you a nested structure BTW, it is going to result in a list of Vector{Any} and Vector{Float64}
