## |: y (Transpose)

Reverses the axes of an array y.

ii=: ] {. [: i. 10 #~ #   NB. utility verb: make self-indexing array
]y=: ii 2 3 4             NB. sample value of shape: 2 3 4
0   1   2   3
10  11  12  13
20  21  22  23

100 101 102 103
110 111 112 113
120 121 122 123
\$ y
2 3 4
\$ |:y
4 3 2

|:y
0 100
10 110
20 120

1 101
11 111
21 121

2 102
12 112
22 122

3 103
13 113
23 123

### Common uses

Transpose a 2D matrix

]z=: 2 3 \$ 'abcdef'   NB. sample mx of shape: 2 3
abc
def
|:z
be
cf

## x |: y (Transpose)

Rearranges the axes of an array y.

The axis having index x becomes the new last axis

y=: ii 2 3 4 5 6

\$ 0|:y
3 4 5 6 2
\$ 1|:y
2 4 5 6 3

x may be a list of axes, in which case all those axes go to the rear, in the order specified

\$ (0 1)|:y
4 5 6 2 3
\$ (1 0)|:y
4 5 6 3 2

If x is boxed (or contains boxed lists of indexes) then the axes thus "boxed together" get run together

\$ (<0 1)|:y
4 5 6 2
• If 2 or more axes are run together, this means they are replaced by a single axis consisting of the diagonal elements of the subarray so-formed.

The old axes 0 1 (which form a subarray of shape (2 3)) get replaced by a single axis of 2 entries, the diagonal of the subarray.

### Common uses

Extracting the diagonal of a square matrix

]z=: ii 3 3
0  1  2
10 11 12
20 21 22
(<0 1) |: z
0 11 22