⌷ — Index
Keys: Alt-q Backslash. Ranks: ∞ monadic, 1 ∞ dyadic
I⌷Y indexes Y. The left argument has one item for each leading axis of Y. Axes that it omits are taken whole. ⌷Y is identity. A subscript writes a single position: m₁ is 1⌷m. After an array, Dot indexing is ⌷: x.[I] is [I]⌷x.
m←3 4⍴⍳12
1⌷m ⍝ 4 5 6 7
1 2⌷m ⍝ 6Each item of the left argument is a single position, an array of positions, or ∞. Selecting with a single position drops that axis from the result. Selecting with an array of positions puts the array’s shape in place of the axis. An array of positions for one axis is one item, as in [[2 0]], because [2 0] gives a position on each of two axes.
v←10 20 30
[[2 0]]⌷v ⍝ 30 10
m←3 4⍴⍳12
[1 2;0 3]⌷m ⍝ [4 7⋄8 11]Positions count from 0. Negative positions count from the end. ¯1 is the last position.
v←10 20 30
¯1⌷v ⍝ 30
[[¯1 0]]⌷v ⍝ 30 10An array of positions whose items are vectors does choose indexing. Each vector is one coordinate, with one position for each axis of Y.
m←3 4⍴⍳12
[[0 1;2 ¯1]]⌷m ⍝ 1 11∞ takes a whole axis, and ¯∞ takes it in reverse order. They are valid only as a whole item, not inside an array of positions.
m←3 4⍴⍳12
∞ 1⌷m ⍝ 1 5 9
¯∞ ∞⌷m ⍝ ⊖3 4⍴⍳12On a keyed axis, a string is one key.
T←"aa" "bb":1 2
"bb"⌷T ⍝ 2Assignment through ⌷ replaces the selected items. A missing key is added, even on an axis with no keys.
x←10 20 30
(¯1⌷x)←9
x ⍝ 10 20 9
T←"aa" "bb":1 2
("cc"⌷T)←3
T ⍝ "aa" "bb" "cc":1 2 3With an axis, ⌷⍠K applies the left argument’s items to the axes K.
1⌷⍠1 (3 4⍴⍳12) ⍝ 1 5 9Inverse
⌷⁻¹Y is ⌷Y.
⌷⁻¹1 2 ⍝ 1 2Errors
LENGTH: more items than axesINDEX: position outside its axis, missing keyDOMAIN: non-integral position,∞or¯∞inside an array of positions