indexswap rearranges the indices of a tensor. It is one of two
generalizations of the matrix transpose operation (cf.
indexswap takes at least one argument which is the tensor on which index
swapping is to be performed. One or two additional arguments may be
provided to specify the indices to be swapped. If no additional arguments
are provided, the first and second indices of the tensor are swapped
(equivalent the matrix transpose operation). With one additional
argument, the specified index is swapped with the one following it (e.g.,
if 2 is specified, the second and third indices will be swapped). If two
additional arguments are provided, they specify the indices to be swapped.
The actual indices used will be constrained to be between 1 and the rank of
For example, given x[a,b,c,d], the command
produces a tensor y such that y[a,b,c,d] = x[a,d,c,b]. In this
example, the element that was in position [a,b,c,d] in x will be
in position [a,d,c,b] in y.
Special cases: If
indexswap is given a scalar (rank 0 tensor) as input,
it just returns the scalar. For a vector (tensor of rank 1),
transposes the 1-by-n matrix (row vector) to an n-by-1 matrix (column