# How to concatenate these two arrays?

**URL:** https://discourse.julialang.org/t/how-to-concatenate-these-two-arrays/77129
**Category:** General Usage
**Tags:** question, arrays
**Created:** [February 26, 2022, 4:10pm UTC](https://discourse.julialang.org/t/how-to-concatenate-these-two-arrays/77129 "2022-02-26T16:10:14Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![leon](https://avatars.discourse-cdn.com/v4/letter/l/dc4da7/32.png) [@leon](https://discourse.julialang.org/u/leon)
#### Post date: [February 26, 2022, 4:10pm UTC](https://discourse.julialang.org/t/how-to-concatenate-these-two-arrays/77129/1 "2022-02-26T16:10:14Z")

</div>

For example, I have two arrays A and B as below:

```julia
A = rand(5,3);
B = rand(5,3,2);

```

How do I concatenate them into C with the size of 5,3,3, so that:  
C[:, :, 1] = A;  
C[:, :, 2:3] = B;

Many thanks.

---

<div class="post-metadata">

### Author: ![rafael.guerra](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rafael.guerra/32/216610_2.png) [@rafael.guerra](https://discourse.julialang.org/u/rafael.guerra)
#### Post date: [February 26, 2022, 4:16pm UTC](https://discourse.julialang.org/t/how-to-concatenate-these-two-arrays/77129/2 "2022-02-26T16:16:18Z")

</div>

Maybe this:

```julia
C = [A;;; B]

```

---

<div class="post-metadata">

### Author: ![leon](https://avatars.discourse-cdn.com/v4/letter/l/dc4da7/32.png) [@leon](https://discourse.julialang.org/u/leon)
#### Post date: [February 26, 2022, 4:21pm UTC](https://discourse.julialang.org/t/how-to-concatenate-these-two-arrays/77129/3 "2022-02-26T16:21:14Z")

</div>

Many thanks!

It works. However, my real world B has 50 layers, do I really need to add 50 semi-colons?

I can also add A to the end, but the below gives me an error.  
`C = [B; A];`

Here is the error:  
`DimensionMismatch("mismatch in dimension 3 (expected 2 got 1)")`

---

<div class="post-metadata">

### Author: ![rafael.guerra](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rafael.guerra/32/216610_2.png) [@rafael.guerra](https://discourse.julialang.org/u/rafael.guerra)
#### Post date: [February 26, 2022, 4:23pm UTC](https://discourse.julialang.org/t/how-to-concatenate-these-two-arrays/77129/4 "2022-02-26T16:23:49Z")

</div>

> [@leon](#):
>
> my real world B has 50 layers,

Please report real world `size(A)` and `size(B)`

---

<div class="post-metadata">

### Author: ![leon](https://avatars.discourse-cdn.com/v4/letter/l/dc4da7/32.png) [@leon](https://discourse.julialang.org/u/leon)
#### Post date: [February 26, 2022, 4:27pm UTC](https://discourse.julialang.org/t/how-to-concatenate-these-two-arrays/77129/5 "2022-02-26T16:27:48Z")

</div>

Size(A) = 360x180  
Size(B) = 360x180x50

My goal is to create a new array with the size of 360x180x51.

Thanks.

---

<div class="post-metadata">

### Author: ![rafael.guerra](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rafael.guerra/32/216610_2.png) [@rafael.guerra](https://discourse.julialang.org/u/rafael.guerra)
#### Post date: [February 26, 2022, 4:29pm UTC](https://discourse.julialang.org/t/how-to-concatenate-these-two-arrays/77129/6 "2022-02-26T16:29:44Z")

</div>

All good then, the result will have `size(C) == (360, 180, 51)`

---

<div class="post-metadata">

### Author: ![leon](https://avatars.discourse-cdn.com/v4/letter/l/dc4da7/32.png) [@leon](https://discourse.julialang.org/u/leon)
#### Post date: [February 26, 2022, 4:32pm UTC](https://discourse.julialang.org/t/how-to-concatenate-these-two-arrays/77129/7 "2022-02-26T16:32:59Z")

</div>

It works! Many thanks. 👍

> [@rafael.guerra](#):
>
> `C = [A;;; B]`
