# Put vector of vector into vector of vector without for loop

**URL:** https://discourse.julialang.org/t/put-vector-of-vector-into-vector-of-vector-without-for-loop/16826
**Category:** General Usage
**Created:** [October 26, 2018, 2:49pm UTC](https://discourse.julialang.org/t/put-vector-of-vector-into-vector-of-vector-without-for-loop/16826 "2018-10-26T14:49:06Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![zsoerenm](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/zsoerenm/32/664_2.png) [@zsoerenm](https://discourse.julialang.org/u/zsoerenm)
#### Post date: [October 26, 2018, 2:49pm UTC](https://discourse.julialang.org/t/put-vector-of-vector-into-vector-of-vector-without-for-loop/16826/1 "2018-10-26T14:49:06Z")

</div>

Consider the following minimal example:

```julia
A = [Vector{Int}(undef, 5) for i = 1:4]
a = [zeros(Int, 2) for i = 1:4]

```

I’d like to put `a` into the first 2 inner indices of `A` without a for loop. Is that possible?  
Something like:

```julia
A[:][1:2] = a

```

but this errors with:

```julia
ERROR: DimensionMismatch("tried to assign 4 elements to 2 destinations")

```

---

<div class="post-metadata">

### Author: ![foobar\_lv2](https://avatars.discourse-cdn.com/v4/letter/f/ee59a6/32.png) [@foobar\_lv2](https://discourse.julialang.org/u/foobar_lv2)
#### Post date: [October 26, 2018, 2:58pm UTC](https://discourse.julialang.org/t/put-vector-of-vector-into-vector-of-vector-without-for-loop/16826/2 "2018-10-26T14:58:26Z")

</div>

```julia
julia> A[1:2] .= a[1:2]; A
4-element Array{Array{Int64,1},1}:
 [0, 0]         
 [0, 0]         
 [1, 2, 3, 4, 5]
 [1, 2, 3, 4, 6]

```

---

<div class="post-metadata">

### Author: ![zsoerenm](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/zsoerenm/32/664_2.png) [@zsoerenm](https://discourse.julialang.org/u/zsoerenm)
#### Post date: [October 26, 2018, 3:03pm UTC](https://discourse.julialang.org/t/put-vector-of-vector-into-vector-of-vector-without-for-loop/16826/3 "2018-10-26T15:03:46Z")

</div>

Thank you, but it is not exactly what I wanted.  
Consider `A` and `a` like

```julia
A = [ones(4) for i = 1:4]
4-element Array{Array{Float64,1},1}:
 [1.0, 1.0, 1.0, 1.0]
 [1.0, 1.0, 1.0, 1.0]
 [1.0, 1.0, 1.0, 1.0]
 [1.0, 1.0, 1.0, 1.0]

julia> a = [zeros(2) for i = 1:4]
4-element Array{Array{Float64,1},1}:
 [0.0, 0.0]
 [0.0, 0.0]
 [0.0, 0.0]
 [0.0, 0.0]

```

The output I like would be:

```julia
4-element Array{Array{Float64,1},1}:
 [0.0, 0.0, 1.0, 1.0]
 [0.0, 0.0, 1.0, 1.0]
 [0.0, 0.0, 1.0, 1.0]
 [0.0, 0.0, 1.0, 1.0]

```

---

<div class="post-metadata">

### Author: ![oliver](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/oliver/32/19264_2.png) [@oliver](https://discourse.julialang.org/u/oliver)
#### Post date: [October 26, 2018, 3:08pm UTC](https://discourse.julialang.org/t/put-vector-of-vector-into-vector-of-vector-without-for-loop/16826/4 "2018-10-26T15:08:16Z")

</div>

> [@foobar\_lv2](#):
>
> .=

I get,

`ERROR: UndefVarError: .= not defined`

---

<div class="post-metadata">

### Author: ![mbauman](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mbauman/32/31082_2.png) [@mbauman](https://discourse.julialang.org/u/mbauman)
#### Post date: [October 26, 2018, 3:10pm UTC](https://discourse.julialang.org/t/put-vector-of-vector-into-vector-of-vector-without-for-loop/16826/5 "2018-10-26T15:10:33Z")

</div>

Are you still using Julia 0.4? I highly recommend you upgrade.
