manipulate single dimension of a Matrix, Vector, or Array as a flat Matrix and transpose
DataTranspose(A, rows, cols, dim)
rectangular storage Matrix, Vector, or Array of any data type and ordering
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)
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)
(optional) non-negative integer; dimension to transpose; assumed to be 1 if not specified
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]);
is treated as a Matrix
M := Matrix([[1,2,3],[4,5,6]],order=C_order);
and the vector data after the transpose
can be seen as storage for the transpose.
M := Matrix([[1,4],[2,5],[3,6]],order=C_order);
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);
when transformed with respect to the second dimension looks like
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](..).
The DataTranspose command is thread safe as of Maple 2023, provided that the rtable A is not shared between threads.
For more information on thread safety, see index/threadsafe.
A demonstration of how to use DataTranspose to compute the transpose of a non-square C_order Matrix in-place
M ≔ Matrix⁡4,3,i,j→10⁢i+j,order=C_order
Generate a 1-D representation of the Matrix.
MV ≔ Alias⁡M,12,row
Transpose the data.
Alias as a 3 x 4 Matrix
Note: The data of the original Matrix has been changed.
A non-square Fortran_order Matrix is similar, but the call to DataTranspose requires the dimensions be reversed.
M ≔ Matrix⁡4,3,i,j→10⁢i+j,order=Fortran_order
Download Help Document