transpose - permute the axes of an array
arr.transpose()
arr.transpose(permutation)
The transpose() method returns a copy of
arr with its axes permuted. By default, it reverses the order
of the axes. This is similar to APL ⍉
arr and code ⍉ arr.
If a permutation vector is provided, it must be an array of integers with the same length as the rank of arr. Each element specifies the index of the source axis that should be mapped to the corresponding destination axis.
If each element of permutation is unique, it simply specifies a new order for the result axes. If an element in permutation is repeated, then axes of the array are mapped together and the rank of the result will be less than the original array. Additionally, the maximum axis allowed to be present in permutation is reduced. If the axes that are mapped together are of different lengths, the shorter axis controls the number of elements for the destination array along that axis. In effect, repeated axes traverse a diagonal of the original array.
A new array containing the same data as arr, but with a different shape and stride layout.
ArgCheck if an incorrect number of arguments
is provided.
ShapeCheck if the
permutation vector length does not match the rank of
arr.
RangeCheck if any element of
the permutation vector is not a valid axis index or if an axis
is repeated.
a = [[1, 2, 3], [4, 5, 6]]
a.transpose()
1 4
2 5
3 6
a = [2,3,4].iterate()
a.transpose()
0 12
4 16
8 20
1 13
5 17
9 21
2 14
6 18
10 22
3 15
7 19
11 23
a.transpose([1,0,2])
0 1 2 3
12 13 14 15
4 5 6 7
16 17 18 19
8 9 10 11
20 21 22 23
// Repeat an axis. Traverses a diagonal of the array.
a.transpose([0,0,1])
0 1 2 3
16 17 18 19