## ³ Transpose

### Monadic (one-argument) form:

Transpose reverses the order of the axes of an array. Thus the first row of a matrix becomes the first column and vice versa, and similarly for arrays of more dimensions. It has no effect on scalars or vectors.

                 TABLE
           1 2 3
           6 7 8
                 ³ TABLE
           1 6
           2 7
           3 8
                 ³ 1 2 3
           1 2 3                          (Has no effect on a vector)
                 DATA „ 12 4 9 ½ ¼ 432
                 ½ DATA
           12 4 9
                 ½ ³ DATA
           9 4 12
                 DATA[1;;2]=(³DATA)[2;;1]
           1 1 1 1

### Dyadic (two-argument) form:

Changes the order of the rows and columns in the right-hand argument according to instructions in the left-hand argument and selects a subset of the right argument. There must be as many elements in the left argument as there are dimensions in the right. This operation has most effect when applied to data which has more than two dimensions. There must be a number in the left-hand argument for each dimension of the result. The result can have any rank greater than zero and not greater than the right argument. Thus for a rank 3 result you must have the numbers 1 2 3 appearing at least once each in the left argument. The positions of the values within the left argument correspond to the axes of the right argument and the values of the left argument refer to the axes of the result.

There are two cases to consider. The first is where all numbers in the left argument are unique. In this case all axes (and all elements) of the right argument appear in the result.

                 TABLE
           1  2
           3  6
           9 10
                 2 1 ³ TABLE             (First element of left argument shows that
           1 3  9                         axis 1 of TABLE becomes axis 2 of result.
           2 6 10                         Same as one argument ³)
                 1 2 ³TABLE              (Co-ordinates stay in their original
           1  2                           order so matrix is unchanged)
           3  6
           9 10
                 ½DATA
           12 4 9
                 ½3 1 2³DATA             (1st axis of DATA becomes 3rd axis of
           4 9 12                         result, 2nd axis of DATA the 1st, etc)
                 DATA[10;3;7]=(3 1 2³DATA)[3;7;10]
           1

When there are repetitions within the left argument, then the appropriate axes of the right argument will be mapped together and the rank of the result will be less than that of the right argument. Thus if the left argument to ³ is 1 2 1 then axis 1 of the result is formed from axes 1 and 3 of the right argument. This is done by selecting those elements whose position is the same on those axes. The operation is selecting diagonals. A simple case is when a rank 1 result is specified (a vector):

                 TABLE1
           1  2
           3  4
                 1 1 ³ TABLE1            (Result is those elements whose row and
           1 4                            column positions match - [1;1] and [2;2])

                 ½DATA
           12 4 9
                 ½1 2 1³DATA
           9 4
                 DATA[4;3;4]=(1 2 1³DATA)[4;3]
           1

If the axes that are being mapped together are of different lengths, those positions that are common are only as many as the length of the shortest axis.

Transpose can be used in selective specification.

Topic: APLX Help : Help on APL language : APL Primitives : ³ Transpose

[ Previous | Next | Contents | Index ]