Indexing


 * This page is about the concept of extracting items from an array. See Index for the concept of a location in an array. See Bracket indexing, Index (function), Pick, and Select for the primitives designed for indexing.

In the APL array model, indexing refers to the operation of extracting one or more elements from an array based on some specification of indices. All indexing operations are subject to index origin in languages which have such a concept.

Rectangular indexing
Rectangular indexing selects indices along each axis of a given array. This indexing mode is usually implemented as Bracket indexing  and Squad indexing. Rectangular indexing has an important property: If rectangular indexing is applied to a matrix, the elements at four corners of a rectangle still form a rectangle in the result. This property generalizes to four elements of a higher-rank array for that share an index over all but two axes.

Relationship to leading axis theory
For implementations that support leading axis theory, it is common to select cells or especially major cells of an array. In these implementations, Squad can be used with short left argument so that the omitted trailing axes can be selected as-is. A few implementations also support Select, the primitive dedicated to selecting major cells.

Replicate as a special case
Various forms of Replicate can be used to select one or more indices over a single axis. applies to the last axis,  to the first, and   applies to the K-th axis. All the other axes are kept intact. The main difference from other indexing primitives is that X does not specify the indices; instead, it specifies how many copies of the corresponding indices to include in the result.

Non-rectangular indexing
Non-rectangular indexing selects multi-dimensional indices from the entire array. This only works with nested array model because the index specification must contain vectors as its elements. A few APL implementations support this form of indexing as a mode of Bracket indexing.

Deep indexing
In nested array model, a need to access items through layers of nesting arises. Deep indexing uses a vector of indices over multiple layers to fetch a deeply nested item. This mode of indexing is supported by Pick, and as a mode of Bracket indexing in a few implementations.