# Help reshaping a 3D array

**URL:** https://discourse.julialang.org/t/help-reshaping-a-3d-array/26525
**Category:** New to Julia
**Tags:** question
**Created:** [July 18, 2019, 9:40pm UTC](https://discourse.julialang.org/t/help-reshaping-a-3d-array/26525 "2019-07-18T21:40:34Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![Yoshua](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yoshua/32/8872_2.png) [@Yoshua](https://discourse.julialang.org/u/Yoshua)
#### Post date: [July 18, 2019, 9:40pm UTC](https://discourse.julialang.org/t/help-reshaping-a-3d-array/26525/1 "2019-07-18T21:40:34Z")

</div>

Hello! I want to make a 3D array. From this I will group three different data vectors to put in this 3-D array. However, I’m having problem with the reshape function.

Img = reshape([[KrogagerR],[KrogagerG],[KrogagerB]], (lin, col, 3))  
but, this giving the error: DimensionMismatch(“new dimensions (7075, 3300, 3) must be consistent with array size 3”)

---

<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: [July 19, 2019, 1:50am UTC](https://discourse.julialang.org/t/help-reshaping-a-3d-array/26525/2 "2019-07-19T01:50:53Z")

</div>

When you write `x = [r, g, b]`, you’re actually creating a 3-element array of arrays. In other words, accessing `x[1]` is going to give you the entire `r` vector. When you write `x = [[r], [g], [b]]`, you’re further nesting each vector inside an additional one-element array.

What you probably want is to _concatenate_ the arguments together into one flattened structure. A great way to do this is with the `cat` function — with it you can specify which dimension you want things to concatenate across. In this case, you can do `cat(r, g, b, dims=3)` — which will “just work” if your individual components are already matrices in the shape of your image. If they’re vectors, well, then you’ll end up with an `Nx1x3` array, which you can then reshape into the dimensions you’re after.

(I split this out from the other thread as it’s an unrelated question)

---

<div class="post-metadata">

### Author: ![Yoshua](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yoshua/32/8872_2.png) [@Yoshua](https://discourse.julialang.org/u/Yoshua)
#### Post date: [July 23, 2019, 11:05pm UTC](https://discourse.julialang.org/t/help-reshaping-a-3d-array/26525/3 "2019-07-23T23:05:27Z")

</div>

Thank @mbauman. Your idea worked.
