# 3D array reshape error

**URL:** <https://discourse.julialang.org/t/3d-array-reshape-error/40507>\
**Category:** Machine Learning\
**Tags:** question\
**Created:** [May 31, 2020, 11:38am UTC](https://discourse.julialang.org/t/3d-array-reshape-error/40507 "2020-05-31T11:38:07Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![dialektike](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dialektike/32/12141_2.png) [@dialektike](https://discourse.julialang.org/u/dialektike)\
**Post date:** [May 31, 2020, 11:38am UTC](https://discourse.julialang.org/t/3d-array-reshape-error/40507/1 "2020-05-31T11:38:07Z")

</div>

```python
A = np.array(range(1, 9)).reshape(2, 2, 2)

# swap 2nd and 3rd axes:
A.transpose((0, 2, 1))

```

I’m also trying to julia like the above python code.  
trying like this…

```julia
A = reshape(1:8, 2, 2, 2)

# swap 2nd and 3rd axes:
reshape(A, [1, 3, 2])

```

but it is not working…

---

<div class="post-metadata">

**Author:** ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Post date:** [May 31, 2020, 12:42pm UTC](https://discourse.julialang.org/t/3d-array-reshape-error/40507/2 "2020-05-31T12:42:18Z")

</div>

> [@dialektike](#):
>
> `swap 2nd and 3rd axes`

You may be looking for `permutedims`.

---

<div class="post-metadata">

**Author:** ![dialektike](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dialektike/32/12141_2.png) [@dialektike](https://discourse.julialang.org/u/dialektike)\
**Post date:** [May 31, 2020, 2:22pm UTC](https://discourse.julialang.org/t/3d-array-reshape-error/40507/3 "2020-05-31T14:22:20Z")

</div>

Thank you! l will try! Good! working!

```julia
julia> A = reshape(1:8, 2, 2, 2)
2×2×2 reshape(::UnitRange{Int64}, 2, 2, 2) with eltype Int64:
[:, :, 1] =
 1 3
 2 4

[:, :, 2] =
 5 7
 6 8

julia> permutedims(A, [1, 3, 2])
2×2×2 Array{Int64,3}:
[:, :, 1] =
 1 5
 2 6

[:, :, 2] =
 3 7
 4 8

```
