4,493
edits
m (Text replacement - "<source" to "<syntaxhighlight") |
m (Text replacement - "</source>" to "</syntaxhighlight>") |
||
Line 1: | Line 1: | ||
{{Built-in|Bracket indexing|<nowiki>[]</nowiki>}}, or simply '''Indexing''', is a special [[primitive function]] which uses the postcircumfix notation <syntaxhighlight lang=apl inline>X[Y]</ | {{Built-in|Bracket indexing|<nowiki>[]</nowiki>}}, or simply '''Indexing''', is a special [[primitive function]] which uses the postcircumfix notation <syntaxhighlight lang=apl inline>X[Y]</syntaxhighlight> instead of a normal prefix function. The result of <syntaxhighlight lang=apl inline>X[Y]</syntaxhighlight> is an array formed with items of X extracted by the [[index]] specification Y. | ||
== Indexing modes == | == Indexing modes == | ||
Line 5: | Line 5: | ||
=== Simple indexing === | === Simple indexing === | ||
Most APL implementations support only this mode of indexing. In its simplest form, <syntaxhighlight lang=apl inline>X[Y]</ | Most APL implementations support only this mode of indexing. In its simplest form, <syntaxhighlight lang=apl inline>X[Y]</syntaxhighlight> on vector X and scalar Y extracts the item of X at index Y. In general, Y can be an array of any shape, with each item being a valid index in X; then <syntaxhighlight lang=apl inline>X[Y]</syntaxhighlight> is a Y-shaped array which contains the indexed results. | ||
<syntaxhighlight lang=apl> | <syntaxhighlight lang=apl> | ||
Line 13: | Line 13: | ||
ABC | ABC | ||
DEA | DEA | ||
</ | </syntaxhighlight> | ||
For higher-[[rank]] array X with rank n, the notation <syntaxhighlight lang=apl inline>X[Y1;Y2;...;Yn]</ | For higher-[[rank]] array X with rank n, the notation <syntaxhighlight lang=apl inline>X[Y1;Y2;...;Yn]</syntaxhighlight> selects the indexes of X over each axis. If some <syntaxhighlight lang=apl inline>Yk</syntaxhighlight> is omitted, it implies all indices of k-th axis is selected, which is equivalent to specifying <syntaxhighlight lang=apl inline>⍳(⍴X)[k]</syntaxhighlight>. The resulting shape is the concatenation of shapes of Y1, Y2, ..., Yn. | ||
<syntaxhighlight lang=apl> | <syntaxhighlight lang=apl> | ||
Line 37: | Line 37: | ||
50 60 70 80 | 50 60 70 80 | ||
170 180 190 200 | 170 180 190 200 | ||
</ | </syntaxhighlight> | ||
The major limitation of this indexing mode is that it only supports rectangular selection. For example, it is not possible to form <syntaxhighlight lang=apl inline>X[1;1],X[2;2]</ | The major limitation of this indexing mode is that it only supports rectangular selection. For example, it is not possible to form <syntaxhighlight lang=apl inline>X[1;1],X[2;2]</syntaxhighlight> from a matrix X by single indexing. | ||
=== Choose indexing === | === Choose indexing === | ||
Line 62: | Line 62: | ||
'Z'[3⍴⊂⍬] ⍝ Scalar X can be indexed using enclosed empty vector | 'Z'[3⍴⊂⍬] ⍝ Scalar X can be indexed using enclosed empty vector | ||
ZZZ | ZZZ | ||
</ | </syntaxhighlight> | ||
=== Reach indexing === | === Reach indexing === | ||
Line 96: | Line 96: | ||
│└───┴─┘│ | │└───┴─┘│ | ||
└───────┘ | └───────┘ | ||
</ | </syntaxhighlight> | ||
== Implementation support == | == Implementation support == |