# Reshape in place

**URL:** <https://discourse.julialang.org/t/reshape-in-place/110356>\
**Category:** General Usage\
**Tags:** array, matrices, reshaping\
**Created:** [February 17, 2024, 8:57pm UTC](https://discourse.julialang.org/t/reshape-in-place/110356 "2024-02-17T20:57:16Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Enlil50](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/enlil50/32/206539_2.png) [@Enlil50](https://discourse.julialang.org/u/Enlil50)\
**Post date:** [February 17, 2024, 8:57pm UTC](https://discourse.julialang.org/t/reshape-in-place/110356/1 "2024-02-17T20:57:16Z")

</div>

I’m trying to reshape in place using:

```julia
using Random
Random.seed!(1)

A = rand(Int8, 4)
show(A)

reshape(A, (2, 2))

println("\n")
show(A)
println("\n")

```

Which should change the algorithm which maps the array into a matrix one, at least following [reshape » Julia Functions](https://www.jlhub.com/julia/manual/en/function/reshape) and [Convert array into matrix in place - #4 by anon74562486](https://discourse.julialang.org/t/convert-array-into-matrix-in-place/55624/4)

However it prints the same object.

If I instead write:

```julia
A = reshape(A, (2, 2))

```

It works, but I don’t know if it just allocates a different A, discarding the previous one

---

<div class="post-metadata">

**Author:** ![jar1](https://avatars.discourse-cdn.com/v4/letter/j/c0e974/32.png) [@jar1](https://discourse.julialang.org/u/jar1)\
**Post date:** [February 17, 2024, 9:04pm UTC](https://discourse.julialang.org/t/reshape-in-place/110356/2 "2024-02-17T21:04:31Z")

</div>

`reshape` makes a view of the same underlying data.

```julia
julia> A = rand(Int, 4)
4-element Vector{Int64}:
   176552731437150339
 -6026423638257492371
  2097435220302348986
  8772925418816777814

julia> B = reshape(A, 2,2)
2×2 Matrix{Int64}:
   176552731437150339 2097435220302348986
 -6026423638257492371 8772925418816777814

julia> B[:] .= 0;

julia> B
2×2 Matrix{Int64}:
 0 0
 0 0

julia> A
4-element Vector{Int64}:
 0
 0
 0
 0

```
