A note added: Although the coding below is correct, it has clearly been superseeded by the following two entries contributed by acer: Entry 1 and Entry 2 in the blog entry Tip: Transpose a pair of indices of an Array. Yesterday I wrote about a method to index an Array, using a procedure of the type `index/method`. Below, using the same sort of procedure, a method for permuting the indices of an Array is given (please feel free to suggest improvements; probably, the else-statement may be written more concisely):
setIndexPermute := proc(permutation::'list'(posint))
	global `index/permute`:
	`index/permute` := proc(indices::list,array::Array,value::list)
		local i,permutedIndices:
		if nargs = 2 then
			return array[op(indices)]:
		else
			permutedIndices := []:
			for i from 1 to nops(indices) do
				permutedIndices := [
					op(permutedIndices),
					indices[permutation[i]]
				]:
			end do:
			array[op(permutedIndices)] := value[1]:
		end if:
	end proc:
end proc:
An example, which performs B[j,k,i] := A[i,j,k] for all (i,j,k):
setIndexPermute([2,3,1]):
A := Array(1..3,1..3,1..3,(i,j,k)->i*j*k);
B := Array(permute,A):
Note that, of course, permutation of indices of an Array works only for Arrays where all dimensions are of equal size. These Arrays may be viewed as tensors, which they are in "Gravitation" from where the above method originates.

Please Wait...