Reshape - Maple Help
For the best experience, we recommend viewing online help using Google Chrome or Microsoft Edge.

ArrayTools

 Reshape
 create a reshaped copy of a Matrix, Vector, or Array

 Calling Sequence Reshape(A, bounds) Reshape(A, bound1, bound2, ...)

Parameters

 A - Matrix, Vector, or Array bounds - list of integers or ranges of integers boundN - integer or range of integers

Description

 • The Reshape command copies the elements of a Matrix, Vector, or Array into a new Matrix, Vector, or Array of a different shape, but does not change the underlying ordering of the elements.  Although the datatype of the rtable remains unchanged, its dimensions are changed to match those given in the bounds.
 • Unlike ArrayTools[Alias], which provides a new view of the existing data within a given rtable without copying it, Reshape instead creates and returns a new rtable containing a complete physical copy of the data in the input. Unless a full copy of the input is required, it is usually much faster to use ArrayTools[Alias], which allows in-place actions to be performed on an rtable as if it were a different shape.
 • The product of the dimension sizes must equal the number of elements in the original rtable.  Each bound in the input can be specified as either a range of integers or a single integer.  Single integers are assumed to represent the upper bound of a range, with the lower bound being 1.  Ranges with lower bounds not equal to 1 are only permissible if the input is of subtype Array.
 • Both Fortran and C order rtables are supported.  Reshape always returns an rtable of the same order as the input.  Note that the location of the elements in the reshaped rtable is entirely dependent on the order of the input rtable.  For example, reshaping a two-dimensional Array into a one-dimensional Array produces very different results depending on the order of the input.
 • If the input rtable has non-rectangular storage, it is converted to rectangular storage before it is reshaped.
 • Reshape creates an rtable whose subtype matches the subtype of the input, where possible.  Matrices are reshaped into Matrices and Vectors if possible, and Vectors are reshaped into Vectors and Matrices, if possible.  Arrays are always reshaped into Arrays.
 • This function is part of the ArrayTools package, so it can be used in the short form Reshape(..) only after executing the command with(ArrayTools).  However, it can always be accessed through the long form of the command by using ArrayTools[Reshape](..).

Examples

 > $\mathrm{with}\left(\mathrm{ArrayTools}\right):$
 > $\mathrm{Reshape}\left(\mathrm{Array}\left(\left[a,b,c,d\right]\right),\left[2,2\right]\right)$
 $\left[\begin{array}{cc}{a}& {c}\\ {b}& {d}\end{array}\right]$ (1)
 > $\mathrm{Reshape}\left(\mathrm{Array}\left(\left[\left[a,b\right],\left[c,d\right]\right]\right),0..3\right)$
 > $\mathrm{Reshape}\left(\mathrm{Vector}\left(\left[1,2,3,4,5,6\right]\right),3,2\right)$
 $\left[\begin{array}{cc}{1}& {4}\\ {2}& {5}\\ {3}& {6}\end{array}\right]$ (2)
 > $\mathrm{Reshape}\left(\mathrm{Vector}\left(\left[1,2,3,4,5,6\right]\right),2,3\right)$
 $\left[\begin{array}{ccc}{1}& {3}& {5}\\ {2}& {4}& {6}\end{array}\right]$ (3)
 > $P≔\mathrm{rtable}\left(\left[\left[1,2,3\right],\left[4,5,6\right]\right],\mathrm{order}=\mathrm{Fortran_order}\right)$
 ${P}{≔}\left[\begin{array}{ccc}{1}& {2}& {3}\\ {4}& {5}& {6}\end{array}\right]$ (4)
 > $Q≔\mathrm{rtable}\left(\left[\left[1,2,3\right],\left[4,5,6\right]\right],\mathrm{order}=\mathrm{C_order}\right)$
 ${Q}{≔}\left[\begin{array}{ccc}{1}& {2}& {3}\\ {4}& {5}& {6}\end{array}\right]$ (5)
 > $\mathrm{Reshape}\left(P,1..6\right)$
 $\left[\begin{array}{cccccc}{1}& {4}& {2}& {5}& {3}& {6}\end{array}\right]$ (6)
 > $\mathrm{Reshape}\left(Q,1..6\right)$
 $\left[\begin{array}{cccccc}{1}& {2}& {3}& {4}& {5}& {6}\end{array}\right]$ (7)