Index: Difference between revisions

Jump to navigation Jump to search
207 bytes added ,  22:05, 10 September 2022
m
Text replacement - "</source>" to "</syntaxhighlight>"
m (Text replacement - "<source" to "<syntaxhighlight")
Tags: Mobile edit Mobile web edit
m (Text replacement - "</source>" to "</syntaxhighlight>")
 
Line 11: Line 11:
(⍴i) ≡ ⍴⍴A
(⍴i) ≡ ⍴⍴A
∧/ (⎕IO≤i) ∧ (i<(⍴A)-⎕IO)
∧/ (⎕IO≤i) ∧ (i<(⍴A)-⎕IO)
</source>
</syntaxhighlight>
to describe the possible indices <syntaxhighlight lang=apl inline>i</source> for an array <syntaxhighlight lang=apl inline>A</source>.
to describe the possible indices <syntaxhighlight lang=apl inline>i</syntaxhighlight> for an array <syntaxhighlight lang=apl inline>A</syntaxhighlight>.


The elements of an array then correspond one-to-one with valid indices for that array (while two elements may have the same value as arrays, they are still considered to be different elements). Using [[Squad indexing]], the element at index <syntaxhighlight lang=apl inline>i</source> is the sole element of [[scalar]] <syntaxhighlight lang=apl inline>i⌷A</source>.
The elements of an array then correspond one-to-one with valid indices for that array (while two elements may have the same value as arrays, they are still considered to be different elements). Using [[Squad indexing]], the element at index <syntaxhighlight lang=apl inline>i</syntaxhighlight> is the sole element of [[scalar]] <syntaxhighlight lang=apl inline>i⌷A</syntaxhighlight>.


When indexing into a [[scalar]] array, there is only one valid index: the [[empty]] numeric vector <syntaxhighlight lang=apl inline>⍴0</source>, or [[Zilde]]. There are no valid indices for an [[empty]] array, because it has no elements.
When indexing into a [[scalar]] array, there is only one valid index: the [[empty]] numeric vector <syntaxhighlight lang=apl inline>⍴0</syntaxhighlight>, or [[Zilde]]. There are no valid indices for an [[empty]] array, because it has no elements.


=== Index of an axis ===
=== Index of an axis ===
Line 22: Line 22:
The indices and [[shape]] of an array both contain one element for each axis. Because these objects are [[vector]]s, each has an element ordering and indices of its own. These indices are called ''axis indices'', and in addition to their implicit use in ordering the shape and index vectors, they are also used directly to refer to axes, for example in [[dyadic Transpose]] and when specifying a [[function axis]].
The indices and [[shape]] of an array both contain one element for each axis. Because these objects are [[vector]]s, each has an element ordering and indices of its own. These indices are called ''axis indices'', and in addition to their implicit use in ordering the shape and index vectors, they are also used directly to refer to axes, for example in [[dyadic Transpose]] and when specifying a [[function axis]].


In some cases, such as [[Laminate]], [[function axis]] may allow a non-integer value. Such a value indicates an axis that exists in the result but not in the argument. It must lie strictly between <syntaxhighlight lang=apl inline>⎕IO-1</source> and <syntaxhighlight lang=apl inline>⎕IO+r</source> for an array of [[rank]] <syntaxhighlight lang=apl inline>r</source>. For a specified axis <syntaxhighlight lang=apl inline>i</source>, the axis will be inserted between axes <syntaxhighlight lang=apl inline>⌊i</source> and <syntaxhighlight lang=apl inline>⌈i</source>, or before every axis if <syntaxhighlight lang=apl inline>⌊i</source> is not a valid axis and after every axis if <syntaxhighlight lang=apl inline>⌈i</source> is not a valid axis (for an [[empty array]], both exceptions hold).
In some cases, such as [[Laminate]], [[function axis]] may allow a non-integer value. Such a value indicates an axis that exists in the result but not in the argument. It must lie strictly between <syntaxhighlight lang=apl inline>⎕IO-1</syntaxhighlight> and <syntaxhighlight lang=apl inline>⎕IO+r</syntaxhighlight> for an array of [[rank]] <syntaxhighlight lang=apl inline>r</syntaxhighlight>. For a specified axis <syntaxhighlight lang=apl inline>i</syntaxhighlight>, the axis will be inserted between axes <syntaxhighlight lang=apl inline>⌊i</syntaxhighlight> and <syntaxhighlight lang=apl inline>⌈i</syntaxhighlight>, or before every axis if <syntaxhighlight lang=apl inline>⌊i</syntaxhighlight> is not a valid axis and after every axis if <syntaxhighlight lang=apl inline>⌈i</syntaxhighlight> is not a valid axis (for an [[empty array]], both exceptions hold).


=== Ravel index ===
=== Ravel index ===


The [[ravel]] of an array can be used to define another kind of index selecting one of its [[element]]s. The '''ravel index''' is a [[scalar]] (although it could equivalently be defined as a [[singleton]] [[vector]]) which corresponds to an ordinary index by the relation <syntaxhighlight lang=apl inline>r⌷A</source> {{←→}} <syntaxhighlight lang=apl inline>i⌷,A</source> where <syntaxhighlight lang=apl inline>r</source> is the ravel index and <syntaxhighlight lang=apl inline>i</source> the ordinary index of an element in <syntaxhighlight lang=apl inline>A</source>. Using [[Encode]] and [[Decode]] we may write <syntaxhighlight lang=apl inline>r</source> {{←→}} <syntaxhighlight lang=apl inline>(⍴A)⊥i</source> and <syntaxhighlight lang=apl inline>i</source> {{←→}} <syntaxhighlight lang=apl inline>(⍴A)⊤r</source> assuming index origin 0.
The [[ravel]] of an array can be used to define another kind of index selecting one of its [[element]]s. The '''ravel index''' is a [[scalar]] (although it could equivalently be defined as a [[singleton]] [[vector]]) which corresponds to an ordinary index by the relation <syntaxhighlight lang=apl inline>r⌷A</syntaxhighlight> {{←→}} <syntaxhighlight lang=apl inline>i⌷,A</syntaxhighlight> where <syntaxhighlight lang=apl inline>r</syntaxhighlight> is the ravel index and <syntaxhighlight lang=apl inline>i</syntaxhighlight> the ordinary index of an element in <syntaxhighlight lang=apl inline>A</syntaxhighlight>. Using [[Encode]] and [[Decode]] we may write <syntaxhighlight lang=apl inline>r</syntaxhighlight> {{←→}} <syntaxhighlight lang=apl inline>(⍴A)⊥i</syntaxhighlight> and <syntaxhighlight lang=apl inline>i</syntaxhighlight> {{←→}} <syntaxhighlight lang=apl inline>(⍴A)⊤r</syntaxhighlight> assuming index origin 0.


The correspondence between indices and ravel indices is governed by [[ravel order]]. For more information, see [[Axis ordering]].
The correspondence between indices and ravel indices is governed by [[ravel order]]. For more information, see [[Axis ordering]].

Navigation menu