ArrayTools - Maple Programming Help

Online Help

All Products    Maple    MapleSim


Home : Support : Online Help : Programming : Low-level Manipulation : Matrices, Vectors, and Arrays : ArrayTools : ArrayTools/DataTranspose

ArrayTools

  

DataTranspose

  

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

 

Calling Sequence

Parameters

Description

Examples

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]);

V123456

(1)
  

is treated as a Matrix

M := Matrix([[1,2,3],[4,5,6]],order=C_order);

M123456

(2)
  

and the vector data after the transpose

ArrayTools:-DataTranspose(V,2,3), V;

142536

(3)
  

can be seen as storage for the transpose.

M := Matrix([[1,4],[2,5],[3,6]],order=C_order);

M142536

(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);

V123456789101112

(5)
  

when transformed with respect to the second dimension looks like

ArrayTools:-DataTranspose(V,2,3,2), V;

142536710811912

(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

withArrayTools:

interfacertablesize=12

10

(7)

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

MMatrix4,3,i,j→10i+j,order=C_order

M111213212223313233414243

(8)

Generate a 1-D representation of the Matrix.

MVAliasM,12,row

MV111213212223313233414243

(9)

Transpose the data.

DataTransposeMV,4,3,MV

112131411222324213233343

(10)

Alias as a 3 x 4 Matrix

AliasM,3,4

112131411222324213233343

(11)

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

Matrix4,3,i,j→10i+j,order=C_order,M

111213212223313233414243,112131411222324213233343

(12)

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

MMatrix4,3,i,j→10i+j,order=Fortran_order

M111213212223313233414243

(13)

MVAliasM,12,row

MV112131411222324213233343

(14)

DataTransposeMV,3,4,MV

111213212223313233414243

(15)

AliasM,3,4

112131411222324213233343

(16)

See Also

ArrayTools

ArrayTools[Alias]

C_order

Fortran_order

interface

Matrix

Vector

 


Download Help Document

Was this information helpful?



Please add your Comment (Optional)
E-mail Address (Optional)
What is ? This question helps us to combat spam