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]);
|
| (1) |
>
|
M := Matrix([[1,2,3],[4,5,6]],order=C_order);
|
| (2) |
|
and the vector data after the transpose
|
>
|
ArrayTools:-DataTranspose(V,2,3), V;
|
| (3) |
|
can be seen as storage for the transpose.
|
>
|
M := Matrix([[1,4],[2,5],[3,6]],order=C_order);
|
| (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.
|
>
|
V := Matrix([[ 1, 2, 3, 4, 5, 6],
[ 7, 8, 9,10,11,12]],order=C_order);
|
| (5) |
|
when transformed with respect to the second dimension looks like
|
>
|
ArrayTools:-DataTranspose(V,2,3,2), V;
|
| (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
|
|
>
|
|
>
|
|
| (7) |
A demonstration of how to use DataTranspose to compute the transpose of a non-square C_order Matrix in-place
>
|
|
| (8) |
Generate a 1-D representation of the Matrix.
>
|
|
| (9) |
Transpose the data.
>
|
|
| (10) |
Alias as a 3 x 4 Matrix
>
|
|
| (11) |
Note: The data of the original Matrix has been changed.
>
|
|
| (12) |
A non-square Fortran_order Matrix is similar, but the call to DataTranspose requires the dimensions be reversed.
>
|
|
| (13) |
>
|
|
| (14) |
>
|
|
| (15) |
>
|
|
| (16) |
|
|