Drop

is a primitive function which removes part of each axis of an array. The removed portions are exactly those that Take would include in its result. Drop is subject to the same extensions as Take, and a detailed description of those extensions and their history is given in that article rather than this one. Unlike Take, Drop never uses fill elements and the result is always a subarray of the argument.

Examples
Use Drop to remove leading or trailing elements from a vector:

Removing more elements than the length of the axis gives an empty result:

When the right argument is a multidimensional array, one element from the left argument is used for each axis. In a language that supports axis specification for Take, or allows a short left argument, you can specify drop amounts for only some axes: other axes will remain unchanged.

Description
The arguments to Drop must be valid arguments to Take, and elements of the left argument are matched to axes of the right in the same way. Like Take, the left argument is subject to scalar rank extension, and in some APLs the right is as well.

Each axis with a matching left argument element  is modified to remove   indices, or all of them if   is larger than the length of the axis. Indices are removed starting from the beginning if  is positive and starting from the end if it is negative (if   is 0, then no indices are removed). Equivalently, for an axis of length,   axes are retained—not dropped—from the axis starting from the opposite side: the end if   is positive and the beginning otherwise. If  is greater than or equal to   for any axis, then the result is empty and shares a prototype with the argument.

APL Model
Drop can be modelled using Take with a complementary length: The code works by modifying the left argument using the right argument's shape. First, the shape is used to restrict the left argument's range so that the maximum number of indices dropped is the length of the axis. Then, the shape is added or subtracted so that the left argument's sign is flipped.

This implementation inherits all argument extensions from Take. The two middle lines are used to support right argument scalar rank extension and the SHARP APL short left argument extension. If Take does not have these extensions then they have no effect and can be removed.

Lessons

 * APL Cultivation

Documentation

 * Dyalog (with axis)


 * APLX


 * J Dictionary, J NuVoc (as )