Index (function): Difference between revisions

Jump to navigation Jump to search
118 bytes added ,  07:37, 8 June 2020
no edit summary
(Created page with ":''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 item...")
 
No edit summary
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 <source lang=apl inline>X⌷Y</source> is an array formed with items of Y extracted by the [[index]] specification X. This function is a proper function alternative to a mode of [[bracket indexing]], which uses a dedicated syntax <source lang=apl inline>Y[X]</source>.
{{Built-in|Index|⌷}}, also called '''Squad Indexing''' after the name of the [[glyph]], is a [[dyadic]] [[primitive function]]. The result of <source lang=apl inline>X⌷Y</source> is an array formed with items of Y extracted by the [[index]] specification X. This function is a proper function alternative to a mode of [[bracket indexing]] (which uses a dedicated syntax <source lang=apl inline>Y[X]</source>), making it usable within [[tacit programming]]. Index 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 <source lang=apl inline>Y[X1;X2;...;Xn] ≡ X1 X2 ... Xn⌷Y</source>. The resulting [[shape]] equals the [[catenate|concatenation]] of the shapes of each element of X.
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 <source lang=apl inline>Y[X1;X2;;Xn] ≡ X1 X2 Xn⌷Y</source>. The resulting [[shape]] equals the [[catenate|concatenation]] of the shapes of each element of X.


<source lang=apl>
<source lang=apl>
Line 27: Line 27:
</source>
</source>


When used with [[function axis]] in the form of <source lang=apl inline>X⌷[K]Y</source>, 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.
When used with [[function axis]] in the form of <source lang=apl inline>X⌷[K]Y</source>, 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.


<source lang=apl>
<source lang=apl>

Navigation menu