ArrayReshape[list,dims]
arranges the elements of list into a rectangular array with dimensions dims.
ArrayReshape[list,dims,padding]
uses the specified padding if list does not contain enough elements.
ArrayReshape
ArrayReshape[list,dims]
arranges the elements of list into a rectangular array with dimensions dims.
ArrayReshape[list,dims,padding]
uses the specified padding if list does not contain enough elements.
Details
- ArrayReshape always gives a rectangular array of the specified dimensions, ignoring the last elements or adding new elements as necessary.
- Elements are arranged in the resulting array so that up to length, Flatten[ArrayReshape[list,dims]] is the same as Flatten[list].
- In ArrayReshape[list,dims,padding], any padding scheme supported by ArrayPad can be specified. The default padding value is 0.
- ArrayReshape works with SparseArray objects.
Examples
open all close allBasic Examples (4)
ArrayReshape[{a, b, c, d, e, f}, {2, 3}]Reshape a vector into a depth-3 array:
ArrayReshape[Range[24], {2, 3, 4}]ArrayReshape[{1, 2, 3, 4, 5, 6, 7}, {5, 3}, x]Use rule-based padding values:
ArrayReshape[{10, 20, 30, 40, 50, 60, 70}, {5, 3}, "Extrapolated"]Scope (1)
Generalizations & Extensions (1)
ArrayReshape works with SparseArray objects:
ArrayReshape[SparseArray[{1 -> 1, 4 -> 5}, 10], {2, 6}, x]MatrixForm[%]Applications (2)
Create an image from a flat list of channel values, effectively inverting the process of flattening image data:
d = ImageData[[image]];
flat = Flatten[d];
ArrayReshape[flat, Dimensions[d]]//Imagea = Table[i + j, {i, 4}, {j, 10}];
ArrayReshape[a, {2, 2, 5, 2}]Properties & Relations (2)
A function based on Partition equivalent to ArrayReshape without padding:
pareshape[list_, dims_] := Fold[Partition, Flatten[list], dims[[-1 ;; 2 ;; -1]]]pareshape[Range[24], {2, 3, 4}]% === ArrayReshape[Range[24], {2, 3, 4}]Reversing matrix dimensions does not give the same element order as Transpose:
m = {{1, 2, 3, 4}, {5, 6, 7, 8}, {9, 10, 11, 12}};ArrayReshape[m, Reverse[Dimensions[m]]]Transpose[m]See Also
Flatten Partition ArrayReduce Fold ArrayPad PadRight Multicolumn
Related Guides
History
Text
Wolfram Research (2012), ArrayReshape, Wolfram Language function, https://reference.wolfram.com/language/ref/ArrayReshape.html.
CMS
Wolfram Language. 2012. "ArrayReshape." Wolfram Language & System Documentation Center. Wolfram Research. https://reference.wolfram.com/language/ref/ArrayReshape.html.
APA
Wolfram Language. (2012). ArrayReshape. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/ArrayReshape.html
BibTeX
@misc{reference.wolfram_2026_arrayreshape, author="Wolfram Research", title="{ArrayReshape}", year="2012", howpublished="\url{https://reference.wolfram.com/language/ref/ArrayReshape.html}", note=[Accessed: 12-June-2026]}
BibLaTeX
@online{reference.wolfram_2026_arrayreshape, organization={Wolfram Research}, title={ArrayReshape}, year={2012}, url={https://reference.wolfram.com/language/ref/ArrayReshape.html}, note=[Accessed: 12-June-2026]}