DataTranspose - Maple Help

ArrayTools

 DataTranspose
 manipulate single dimension of a Matrix, Vector, or Array as a flat Matrix and transpose

 Calling Sequence DataTranspose(A, rows, cols, dim)

Parameters

 A - rectangular storage Matrix, Vector, or Array of any data type and ordering rows - integer; number of rows viewing dimension dim as data storage for a row-major Matrix (or alternatively the number of columns for a column-major Matrix) cols - integer; number of columns viewing dimension dim as data storage for a row-major Matrix (or alternatively the number of rows for a column-major Matrix) dim - (optional) non-negative integer; dimension to transpose; assumed to be 1 if not specified

Description

 • The DataTranspose command performs an in-place transpose with respect to a single dimension of the input Matrix, Vector, or Array as though the data for that dimension represents the storage for a Matrix. The input Matrix, Vector, or Array must have rectangular (dense) storage.
 To understand how this works, you must know how data for row and column-major Matrices is stored. For a description of the two possibilities, see Fortran_order and C_order.
 • This is simplest to understand for a Vector. You can view the input data as storage for a rows x cols C_order Matrix. On output, the data in the Vector is re-arranged so it can be viewed as the storage for a cols x rows C_order Matrix that holds the transpose of the original Matrix.
 For example, the 6 element Vector
 > V := Vector[row]([1,2,3,4,5,6]);
 ${V}{≔}\left[\begin{array}{cccccc}{1}& {2}& {3}& {4}& {5}& {6}\end{array}\right]$ (1)
 is treated as a Matrix
 > M := Matrix([[1,2,3],[4,5,6]],order=C_order);
 ${M}{≔}\left[\begin{array}{ccc}{1}& {2}& {3}\\ {4}& {5}& {6}\end{array}\right]$ (2)
 and the vector data after the transpose
 > ArrayTools:-DataTranspose(V,2,3), V;
 $\left[\begin{array}{cccccc}{1}& {4}& {2}& {5}& {3}& {6}\end{array}\right]$ (3)
 can be seen as storage for the transpose.
 > M := Matrix([[1,4],[2,5],[3,6]],order=C_order);
 ${M}{≔}\left[\begin{array}{cc}{1}& {4}\\ {2}& {5}\\ {3}& {6}\end{array}\right]$ (4)
 • For Matrices and Arrays with more than one dimension, the specified dimension dim is transformed in the same manner as described for a Vector, but this is done for all values of the indices for the other dimensions.
 For example, the Matrix
 > V := Matrix([[ 1, 2, 3, 4, 5, 6],              [ 7, 8, 9,10,11,12]],order=C_order);
 ${V}{≔}\left[\begin{array}{cccccc}{1}& {2}& {3}& {4}& {5}& {6}\\ {7}& {8}& {9}& {10}& {11}& {12}\end{array}\right]$ (5)
 when transformed with respect to the second dimension looks like
 > ArrayTools:-DataTranspose(V,2,3,2), V;
 $\left[\begin{array}{cccccc}{1}& {4}& {2}& {5}& {3}& {6}\\ {7}& {10}& {8}& {11}& {9}& {12}\end{array}\right]$ (6)
 which is the same as for the vector example, but applied twice, once for each row of the Matrix.
 • If the dimension dim is not specified, then it is assumed to be 1.
 Note: For the dimension being transformed, the number of rows times the number of cols specified cannot exceed the number of entries in that dimension.
 • This command can be used in combination with Alias to construct the transpose of a non-square Matrix directly using the same storage of the original Matrix (an in-place transpose). See the following examples.
 • This function is part of the ArrayTools package, so it can be used in the short form DataTranspose(..) only after executing the command with(ArrayTools).  However, it can always be accessed through the long form of the command by using ArrayTools[DataTranspose](..).

Examples

 > $\mathrm{with}\left(\mathrm{ArrayTools}\right):$

A demonstration of how to use DataTranspose to compute the transpose of a non-square C_order Matrix in-place

 > $M≔\mathrm{Matrix}\left(4,3,\left(i,j\right)↦10\cdot i+j,\mathrm{order}=\mathrm{C_order}\right)$
 ${M}{≔}\left[\begin{array}{ccc}{11}& {12}& {13}\\ {21}& {22}& {23}\\ {31}& {32}& {33}\\ {41}& {42}& {43}\end{array}\right]$ (7)

Generate a 1-D representation of the Matrix.

 > $\mathrm{MV}≔\mathrm{Alias}\left(M,\left[12\right],\mathrm{row}\right)$
 ${\mathrm{MV}}{≔}\left[\begin{array}{cccccccccccc}{11}& {12}& {13}& {21}& {22}& {23}& {31}& {32}& {33}& {41}& {42}& {43}\end{array}\right]$ (8)

Transpose the data.

 > $\mathrm{DataTranspose}\left(\mathrm{MV},4,3\right),\mathrm{MV}$
 $\left[\begin{array}{cccccccccccc}{11}& {21}& {31}& {41}& {12}& {22}& {32}& {42}& {13}& {23}& {33}& {43}\end{array}\right]$ (9)

Alias as a 3 x 4 Matrix

 > $\mathrm{Alias}\left(M,\left[3,4\right]\right)$
 $\left[\begin{array}{cccc}{11}& {21}& {31}& {41}\\ {12}& {22}& {32}& {42}\\ {13}& {23}& {33}& {43}\end{array}\right]$ (10)

Note: The data of the original Matrix has been changed.

 > $\mathrm{Matrix}\left(4,3,\left(i,j\right)↦10\cdot i+j,\mathrm{order}=\mathrm{C_order}\right),M$
 $\left[\begin{array}{ccc}{11}& {12}& {13}\\ {21}& {22}& {23}\\ {31}& {32}& {33}\\ {41}& {42}& {43}\end{array}\right]{,}\left[\begin{array}{ccc}{11}& {21}& {31}\\ {41}& {12}& {22}\\ {32}& {42}& {13}\\ {23}& {33}& {43}\end{array}\right]$ (11)

A non-square Fortran_order Matrix is similar, but the call to DataTranspose requires the dimensions be reversed.

 > $M≔\mathrm{Matrix}\left(4,3,\left(i,j\right)↦10\cdot i+j,\mathrm{order}=\mathrm{Fortran_order}\right)$
 ${M}{≔}\left[\begin{array}{ccc}{11}& {12}& {13}\\ {21}& {22}& {23}\\ {31}& {32}& {33}\\ {41}& {42}& {43}\end{array}\right]$ (12)
 > $\mathrm{MV}≔\mathrm{Alias}\left(M,\left[12\right],\mathrm{row}\right)$
 ${\mathrm{MV}}{≔}\left[\begin{array}{cccccccccccc}{11}& {21}& {31}& {41}& {12}& {22}& {32}& {42}& {13}& {23}& {33}& {43}\end{array}\right]$ (13)
 > $\mathrm{DataTranspose}\left(\mathrm{MV},3,4\right),\mathrm{MV}$
 $\left[\begin{array}{cccccccccccc}{11}& {12}& {13}& {21}& {22}& {23}& {31}& {32}& {33}& {41}& {42}& {43}\end{array}\right]$ (14)
 > $\mathrm{Alias}\left(M,\left[3,4\right]\right)$
 $\left[\begin{array}{cccc}{11}& {21}& {31}& {41}\\ {12}& {22}& {32}& {42}\\ {13}& {23}& {33}& {43}\end{array}\right]$ (15)