# Vector of vectors with floats: Type confusion

**URL:** <https://discourse.julialang.org/t/vector-of-vectors-with-floats-type-confusion/115707>\
**Category:** General Usage\
**Tags:** question, type\
**Created:** [June 16, 2024, 1:45am UTC](https://discourse.julialang.org/t/vector-of-vectors-with-floats-type-confusion/115707 "2024-06-16T01:45:07Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Santiago\_Lopez](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/santiago_lopez/32/46298_2.png) [@Santiago\_Lopez](https://discourse.julialang.org/u/Santiago_Lopez)\
**Post date:** [June 16, 2024, 1:45am UTC](https://discourse.julialang.org/t/vector-of-vectors-with-floats-type-confusion/115707/1 "2024-06-16T01:45:07Z")

</div>

I have a vector of vectors `vv`. Each vector `v` in `vv` is of type `Vector{Float32}`:

```julia
julia> unique(typeof.(vv))

1-element Vector{DataType}:
Vector{Float32} (alias for Array{Float32, 1})

```

However,

```julia
julia> typeof(vv)
Vector{Vector} (alias for Array{Array{T, 1} where T, 1})

```

I would have expected the type of `vv` to be `Vector{Vector{Float32}}`. In fact, I’m passing `vv` as argument to a function that expects an argument type `Vector{<:Vector{Float32}}` (of course I’m getting an error).

This behavior is strange. Why is the type of `vv` not `Vector{Vector{Float32}}`?

---

<div class="post-metadata">

**Author:** ![adienes](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/adienes/32/37459_2.png) [@adienes](https://discourse.julialang.org/u/adienes)\
**Post date:** [June 16, 2024, 2:08am UTC](https://discourse.julialang.org/t/vector-of-vectors-with-floats-type-confusion/115707/2 "2024-06-16T02:08:55Z")

</div>

it can depend on how you’ve constructed `vv`

```julia
julia> vv_any = []; push!(vv_any, [1.0f0]);

julia> typeof(vv_any)
Vector{Any} (alias for Array{Any, 1})

julia> vv_f32 = Vector{Float32}[[1.0f0], [2.0f0]];

julia> typeof(vv_f32)
Vector{Vector{Float32}} (alias for Array{Array{Float32, 1}, 1})

julia> foo() = rand() < 0.5 ? Float32[1.0f0] : String[] # not type-stable

julia> vv_typed = [foo() for _ ∈ 1:10];

julia> typeof(vv_typed)
Vector{Vector} (alias for Array{Array{T, 1} where T, 1})

```

It may clear things up to think of variable bindings having types, not just variable values (where the type of the binding must be a supertype of the type of the value it points to)

note that above, both `vv_any` and `vv_typed` are convertible to the type you want via `convert(Vector{Vector{Float32}}, _)`

---

<div class="post-metadata">

**Author:** ![Santiago\_Lopez](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/santiago_lopez/32/46298_2.png) [@Santiago\_Lopez](https://discourse.julialang.org/u/Santiago_Lopez)\
**Post date:** [June 16, 2024, 7:35pm UTC](https://discourse.julialang.org/t/vector-of-vectors-with-floats-type-confusion/115707/3 "2024-06-16T19:35:20Z")

</div>

A clarifying answer. The problem indeed came from the construction of `vv`. Thanks!

---

<div class="post-metadata">

**Author:** ![DNF](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dnf/32/10191_2.png) [@DNF](https://discourse.julialang.org/u/DNF)\
**Post date:** [June 16, 2024, 9:09pm UTC](https://discourse.julialang.org/t/vector-of-vectors-with-floats-type-confusion/115707/4 "2024-06-16T21:09:04Z")

</div>

> [@adienes](#):
>
> It may clear things up to think of variable bindings having types, not just variable values

I don’t understand what you mean by this. The only thing going on here, surely, is that there’s an array which is not parameterize sufficiently narrowly, that is, entirely to do with the type of the value. What does the binding have to do with this?

---

<div class="post-metadata">

**Author:** ![adienes](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/adienes/32/37459_2.png) [@adienes](https://discourse.julialang.org/u/adienes)\
**Post date:** [June 16, 2024, 9:32pm UTC](https://discourse.julialang.org/t/vector-of-vectors-with-floats-type-confusion/115707/5 "2024-06-16T21:32:49Z")

</div>

it’s just a mental model that is probably not entirely technically accurate. all I mean is that the type of the variable is not necessarily equal to the “actual” most concrete type possible for the data that variable points to.
