Reverse

is a monadic function which reorders elements of the argument to go in the opposite direction along a specified axis. The name Reverse is typically used for the primitive, which reverses along the last axis, while  , which reverses along the first axis, is called "Reverse First", "Reverse-down", or similar. In APLs with function axis, either for may use a specified axis which overrides this default choice of axis. In the leading axis model, specifying an axis is discouraged in favor of using  with the Rank operator.

Examples
Reverse flips a matrix horizontally, changing elements to go right to left, and Reverse First flip vertically, so the elements are reordered top to bottom. Since a vector only has one axis, any form of Reverse will reverse along this axis. Reverse with a specified axis can reverse along any of the three dimensions of the array below. The Rank operator can also be used to reverse along a particular axis. While Rank has no effect on Reverse (last), Reverse First with rank  reverses the first axis of each  -cell, or the  'th axis of a rank-  array. Reversing a scalar has no effect: there are no axes to reverse along.

Description
In languages with function axis, exactly one argument axis may be specified.

Reversing a scalar always yields that scalar unchanged. Otherwise, Reverse operates on a particular axis of its argument. This axis is the specified axis if one is given, and otherwise the last axis for, or the first axis for.

The result array has the same shape and elements as the argument array, but the elements go in the opposite direction along the reversal axis: the first in the argument is last in the result, and so on. Consequently if the length of this axis is 0 or 1 then reversing has no effect.

APL model
The reverse of a vector  may be written in any APL, assuming , as. To reverse an arbitrary array Squad indexing with axis (or rank) is helpful.

Lessons

 * APL Cultivation

Documentation

 * Dyalog
 * APLX
 * J Dictionary, NuVoc (only first-axis reverse exists)