# \#reshaping

**URL:** https://discourse.julialang.org/tag/reshaping/693.md

[Latest](https://discourse.julialang.org/latest.md) · [Categories](https://discourse.julialang.org/categories.md) · [Tags](https://discourse.julialang.org/tags.md)

---

## [Repeat and reshape vector into a matrix](https://discourse.julialang.org/t/repeat-and-reshape-vector-into-a-matrix/127451)

<div class="topic-metadata">

**Author:** [@Ju\_ska](https://discourse.julialang.org/u/Ju_ska)\
**Replies:** 9\
**Last updated:** [March 28, 2025, 9:13pm UTC](https://discourse.julialang.org/t/repeat-and-reshape-vector-into-a-matrix/127451 "2025-03-28T21:13:31Z")

</div>

Hi, this is a Python code I’m translating in Julia: import numpy as np val = \[1,2,3,4,5,6\] val\_length = len(val) rpt = 3 np.repeat(val, rpt).reshape((val\_length, rpt)) It gives: \>\>\> val = \[1,2,3,4,5,6\] \>\>\> val\_leng…

---

## [Broadcasting the reshaped data @. versus .=](https://discourse.julialang.org/t/broadcasting-the-reshaped-data-versus/124300)

<div class="topic-metadata">

**Author:** [@raman\_kumar](https://discourse.julialang.org/u/raman_kumar)\
**Replies:** 13\
**Last updated:** [January 1, 2025, 11:48am UTC](https://discourse.julialang.org/t/broadcasting-the-reshaped-data-versus/124300 "2025-01-01T11:48:39Z")

</div>

I am rewriting this code below using broadcasting to improve performance and clarity. var = zeros(Float64, 9, 109, 50) data = rand(9\*109\*50) for j in 1:9 # Extract the slice of data corresponding to the current \`j\` …

---

## [Reshape in place](https://discourse.julialang.org/t/reshape-in-place/110356)

<div class="topic-metadata">

**Author:** [@Enlil50](https://discourse.julialang.org/u/Enlil50)\
**Replies:** 1\
**Last updated:** [February 17, 2024, 9:04pm UTC](https://discourse.julialang.org/t/reshape-in-place/110356 "2024-02-17T21:04:31Z")

</div>

I’m trying to reshape in place using: 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 matri…

---

## [Efficient Broadcasting in Julia: CartesianIndex vs. Reshape](https://discourse.julialang.org/t/efficient-broadcasting-in-julia-cartesianindex-vs-reshape/106929)

<div class="topic-metadata">

**Author:** [@swanchristmas](https://discourse.julialang.org/u/swanchristmas)\
**Replies:** 1\
**Last updated:** [November 30, 2023, 8:12am UTC](https://discourse.julialang.org/t/efficient-broadcasting-in-julia-cartesianindex-vs-reshape/106929 "2023-11-30T08:12:22Z")

</div>

I came across a discussion post on using \[CartesianIndex()\] for singleton insertion in Julia arrays. Intrigued by potential performance differences, I conducted a benchmark comparing it with the reshape method. Benchmar…

---

## [Create data frame using values from vector as columns](https://discourse.julialang.org/t/create-data-frame-using-values-from-vector-as-columns/105416)

<div class="topic-metadata">

**Author:** [@Sandy45](https://discourse.julialang.org/u/Sandy45)\
**Replies:** 6\
**Last updated:** [October 26, 2023, 9:00pm UTC](https://discourse.julialang.org/t/create-data-frame-using-values-from-vector-as-columns/105416 "2023-10-26T21:00:19Z")

</div>

I have data frame which has column say “minutes” and I need to create another data frame using “minutes” as columns as shown below. I was able to create using reshape but values are being concatenated where I need them …

---

## [Nested array replacement](https://discourse.julialang.org/t/nested-array-replacement/102348)

<div class="topic-metadata">

**Author:** [@Denis\_Ivanov](https://discourse.julialang.org/u/Denis_Ivanov)\
**Replies:** 4\
**Last updated:** [August 2, 2023, 8:40pm UTC](https://discourse.julialang.org/t/nested-array-replacement/102348 "2023-08-02T20:40:57Z")

</div>

Hi! I would like to model this behavior on Julia: Substitution System So if we have rules ( 1 =\> \[\[1, 0\], \[1, 1\]\], 0 =\> \[\[0, 0\], \[0, 0\]\] ) and array \[\[1, 0\], \[1, 1\]\] than output should be \[1, 0, 0, 0\], \[1, 1, 0, 0\],…

---

## [Reshape vector of odd length to multi-dimensional array](https://discourse.julialang.org/t/reshape-vector-of-odd-length-to-multi-dimensional-array/76465)

<div class="topic-metadata">

**Author:** [@lln](https://discourse.julialang.org/u/lln)\
**Replies:** 6\
**Last updated:** [February 15, 2022, 12:17am UTC](https://discourse.julialang.org/t/reshape-vector-of-odd-length-to-multi-dimensional-array/76465 "2022-02-15T00:17:43Z")

</div>

Hi, I’m trying to reshape a vector of odd length (15) into a multi-dimensional array and getting a DimensionMismatch("array size 15 must be divisible by the product of the new dimensions (2, Colon())") error, which make…

---

## [Reshape long](https://discourse.julialang.org/t/reshape-long/72257)

<div class="topic-metadata">

**Author:** [@Matthew](https://discourse.julialang.org/u/Matthew)\
**Replies:** 4\
**Last updated:** [November 30, 2021, 3:15pm UTC](https://discourse.julialang.org/t/reshape-long/72257 "2021-11-30T15:15:59Z")

</div>

Hi everyone, I’m loving Julia but am having some difficulties reshaping my dataframe to a “long” format. df = DataFrame(ID = 1:3, sex = \[0,1,0\], inc80 = \[5500,2200,2000\], inc81 = incB, inc82 = incC, …

---

## [Turn vector of matrices into 3D array](https://discourse.julialang.org/t/turn-vector-of-matrices-into-3d-array/69777)

<div class="topic-metadata">

**Author:** [@hannesbecher](https://discourse.julialang.org/u/hannesbecher)\
**Replies:** 6\
**Last updated:** [October 18, 2021, 8:14pm UTC](https://discourse.julialang.org/t/turn-vector-of-matrices-into-3d-array/69777 "2021-10-18T20:14:20Z")

</div>

Background: My simulation program returns a 4x4 matrix. Running many replicates using map() or a vector comprehension, I get a long vector of small matrices. Similar to \[rand(4, 4) for \_ in 1:10000\]. Question: Is there …

---

## [What is the fastest way to turn a 3D array into a vector of 2D arrays?](https://discourse.julialang.org/t/what-is-the-fastest-way-to-turn-a-3d-array-into-a-vector-of-2d-arrays/65729)

<div class="topic-metadata">

**Author:** [@erwanlecarpentier](https://discourse.julialang.org/u/erwanlecarpentier)\
**Replies:** 13\
**Last updated:** [August 3, 2021, 2:56pm UTC](https://discourse.julialang.org/t/what-is-the-fastest-way-to-turn-a-3d-array-into-a-vector-of-2d-arrays/65729 "2021-08-03T14:56:36Z")

</div>

Hi, I wonder what would be the fastest way to turn a 3D array into a vector of 2D arrays. Specifically: the input is an array of size size(inp) = (a, b, c) and I want as output a vector (typeof(out) = Array{Array{UInt8,…

---

## [How many ways can it be reshaped?](https://discourse.julialang.org/t/how-many-ways-can-it-be-reshaped/61530)

<div class="topic-metadata">

**Author:** [@rocco\_sprmnt21](https://discourse.julialang.org/u/rocco_sprmnt21)\
**Replies:** 3\
**Last updated:** [May 21, 2021, 3:24pm UTC](https://discourse.julialang.org/t/how-many-ways-can-it-be-reshaped/61530 "2021-05-21T15:24:43Z")

</div>

I have found a few ways to solve the following problem, but I’m sure there are many others. X=\["Product\_id","Date","Unit","Revenue","Product\_id","Date","Unit","Revenue","Product\_id","Date","Unit","Revenue"\] Y=\["1234","0…
