4,501
edits
No edit summary |
m (Text replacement - "</source>" to "</syntaxhighlight>") |
||
(4 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
:''This article describes a dyadic primitive function that performs indexing into an array. For the concept of array indices, see [[Index]]. For the concept of extracting items from an array, see [[Indexing]].'' | :''This article describes a dyadic primitive function that performs indexing into an array. For the concept of array indices, see [[Index]]. For the concept of extracting items from an array, see [[Indexing]].'' | ||
{{Built-in|Index|⌷}}, also called '''Squad Indexing''' after the name of the [[glyph]], is a [[dyadic]] [[primitive function]]. The result of < | {{Built-in|Index|⌷}}, also called '''Squad Indexing''' after the name of the [[glyph]], is a [[dyadic]] [[primitive function]]. The result of <syntaxhighlight lang=apl inline>X⌷Y</syntaxhighlight> is an array formed with items of Y extracted by the [[index]] specification X. Index is a proper [[function]] alternative to a mode of [[bracket indexing]] (which uses a dedicated syntax <syntaxhighlight lang=apl inline>Y[X]</syntaxhighlight>), making it usable within [[tacit programming]]. It shares its glyph with the monadic [[Materialise]] function. | ||
== Examples == | == Examples == | ||
The left [[argument]] X must be a [[vector]] whose length equals the [[rank]] of the right argument Y and [[depth]] does not exceed 2. Each element of X selects one or more indices over the corresponding [[axis]] of the right argument Y. The result is identical to that of [[bracket indexing]] in that < | The left [[argument]] X must be a [[vector]] whose length equals the [[rank]] of the right argument Y and [[depth]] does not exceed 2. Each element of X selects one or more indices over the corresponding [[axis]] of the right argument Y. The result is identical to that of [[bracket indexing]] in that <syntaxhighlight lang=apl inline>Y[X1;X2;…;Xn] ≡ X1 X2 … Xn⌷Y</syntaxhighlight>. The resulting [[shape]] equals the [[catenate|concatenation]] of the shapes of each element of X. | ||
< | <syntaxhighlight lang=apl> | ||
VEC←111 222 333 444 | VEC←111 222 333 444 | ||
3⌷VEC | 3⌷VEC | ||
Line 25: | Line 25: | ||
⍴(2 1⍴1)(3 4⍴2)⌷MAT | ⍴(2 1⍴1)(3 4⍴2)⌷MAT | ||
2 1 3 4 | 2 1 3 4 | ||
</ | </syntaxhighlight> | ||
When used with [[function axis]] in the form of < | When used with [[function axis]] in the form of <syntaxhighlight lang=apl inline>X⌷[K]Y</syntaxhighlight>, K specifies a subset of [[axes]] of Y to apply indexing on. The axes not mentioned in K are selected without modification; this corresponds to omitted axes in bracket indexing. | ||
< | <syntaxhighlight lang=apl> | ||
⎕←CUBE←10⊥¨⍳2 3 4 | ⎕←CUBE←10⊥¨⍳2 3 4 | ||
111 112 113 114 | 111 112 113 114 | ||
Line 50: | Line 50: | ||
CUBE[;;2] ≡ 2⌷[3]CUBE | CUBE[;;2] ≡ 2⌷[3]CUBE | ||
1 | 1 | ||
</ | </syntaxhighlight> | ||
In some dialects that support [[leading axis theory]], short X in < | In some dialects that support [[leading axis theory]], short X in <syntaxhighlight lang=apl inline>X⌷Y</syntaxhighlight> selects from leading axes of Y. In that case, the trailing axes are selected without modification. | ||
< | <syntaxhighlight lang=apl> | ||
MAT←10⊥¨⍳3 4 ⍝ Same as the first example | MAT←10⊥¨⍳3 4 ⍝ Same as the first example | ||
2⌷MAT ⍝ Second axis omitted | 2⌷MAT ⍝ Second axis omitted | ||
21 22 23 24 | 21 22 23 24 | ||
</ | </syntaxhighlight>{{Works in|[[Dyalog APL]]}} | ||
== Implementation support == | == Implementation support == | ||
This form of indexing is supported in [[J]] as boxed left argument of '''From''' < | This form of indexing is supported in [[J]] as boxed left argument of '''From''' <syntaxhighlight lang=j inline>{</syntaxhighlight>. | ||
== See also == | |||
* [[Pick]] | |||
* [[Select]] | |||
== External links == | == External links == | ||
=== Documentation === | === Documentation === | ||
* [ | * [https://help.dyalog.com/latest/#Language/Primitive%20Functions/Index.htm Dyalog], [https://help.dyalog.com/latest/#Language/Primitive%20Functions/Index%20with%20Axes.htm with axis] | ||
* [http://microapl.com/apl_help/ch_020_020_620.htm APLX] | * [http://microapl.com/apl_help/ch_020_020_620.htm APLX] | ||
* J [https://www.jsoftware.com/help/dictionary/d520.htm Dictionary], [https://code.jsoftware.com/wiki/Vocabulary/curlylf#dyadic Nuvoc] | * J [https://www.jsoftware.com/help/dictionary/d520.htm Dictionary], [https://code.jsoftware.com/wiki/Vocabulary/curlylf#dyadic Nuvoc] | ||
{{APL built-ins}}[[Category:Primitive functions]] | {{APL built-ins}}[[Category:Primitive functions]] |