Next: , Previous: , Up: Matrices and Tensors   [Contents][Index]


4.7 Shifting of Tensor Indices

Command: indexshift matrix index1 …

indexshift rearranges the indices of a tensor. It is one of two generalizations of the matrix transpose operation (cf. indexswap).

indexshift takes at least one argument which is the tensor on which the index shifting is to be performed. One or two additional arguments may be provided to specify the index and the position to which it is to be shifted. If no additional arguments are provided, the first index of the tensor is shifted to the second position (equivalent the matrix transpose operation). If one additional argument is provided, it specifies the index to be shifted, and that index will be shifted "to the right" one position (e.g., if 3 is specified, the third index will be shifted to the forth position). If two additional arguments are provided, the first specifies the index and the second specifies the position to which it is to be shifted. The actual index shifted and its shifted position will be constrained to be between 1 and the rank of the tensor.

For example, given x[a,b,c,d], the command y:indexshift(x,1,3); produces a tensor y such that y[a,b,c,d] ≡ x[b,c,a,d]. In this example, the element that was in position [a,b,c,d] in x will be in position [b,c,a,d] in y.

Special cases: If indexshift is given a scalar (rank 0 tensor) as input, it just returns the scalar. For a vector (tensor of rank 1), indexshift transposes the 1-by-n matrix (row vector) to an n-by-1 matrix (column vector).


Next: Swapping of Tensor Indices, Previous: Tensor contraction, Up: Matrices and Tensors   [Contents][Index]