Transpose

is an ambivalent primitive function which reorders the axes of the right argument array. The name Transpose comes from the fact that monadic application to a matrix yields its transpose. The dyadic usage is sometimes called Rearrange Axes, which better reflects the behavior of the function.

Monadic usage
Monadic Transpose reverses the axes of the right argument. When applied to a matrix, the result is its transpose. Scalar and vector arguments are unaffected.

Dyadic usage
For dyadic usage, the left argument X must be a vector whose length equals the rank of the right argument Y, and the elements must form a range so that  is satisfied.

If all values in X are unique (X forms a permutation over the axes of Y), the axes are reordered by X so that N-th element of X specifies the new position for the N-th axis of Y. This means that, given a multi-dimensional index V of an element in the resulting array,  corresponds to.

When X contains duplicates, the result has rank. For the axes of Y that map to the same resulting axis, only the elements where the indices are equal over those axes are collected. This has the effect of extracting diagonal elements. If the axes are of unequal length, the resulting axis has the length of the shortest of them. This operation can be modeled as computing the resulting shape, then creating the array of its multi-dimensional indices  , then modify each index and fetch the corresponding elements of Y.

Issues
A common mistake in employing dyadic transpose is the "intuitive" interpretation of the left argument as if gives the order in which you want to select dimensions of the right argument for the result. In fact, it gives the new position of each of the dimensions. It is possible to convert between these two representations by "inverting" the permutation with monadic Grade Up.

The reason for the design of  being as it is, is that it allows you to select diagonals by giving one or more dimensions equal mapping, whereas simply selecting dimensions from the right would not allow that. It is therefore the more complete of the two options.

Tutorials

 * APL Cultivation
 * Learning APL
 * Dyalog Webinar

Documentation

 * Dyalog monadic, dyadic
 * APLX
 * J Dictionary, NuVoc
 * BQN