Select (⊇
) (jokingly referred to as Sane Indexing) is a primitive function that allows selecting multiple major cells using indices of the cells. It is equivalent to ⌷⍨∘⊂⍨
and ⌷⍤0 ∞
, only providing a neater notation for such a fundamental concept. It was introduced in Extended Dyalog APL, and then adopted into dzaima/APL and KAP.
Common usage
Select is commonly used to reorder the major cells of an array. For example, the following shuffles any array into random order:
Try it online!
Shuffle←?⍨∘≢⊇⊢
Shuffle 'abcdef'
fbdcea
Without Select, one would have to write Shuffle←⊢⌷⍨∘⊂?⍨∘≢
.
In a case where the left argument is a permutation vector for the right argument, the functionality can rightfully be called Permute.
Select especially cleans up expressions for reordering. An ascending sort can be represented as ⍋⊇⊢
and "sort by" can be written as ⊇⍨∘⍋
:
Try it online!
'abcde' ⊇⍨∘⍋ 3 1 4 1 5
bdace
Potential extension
Select can be defined as ⌷⍨∘⊃⍨⍤0 ∞
thus allowing both the above usage and "scatter point indexing":
1 4 3 ⊇ 4 4⍴⎕A
ABCD
MNOP
IJKL
(1 1)(4 4)(3 4) ⊇ 4 4⍴⎕A
APL
See also
APL built-ins [edit]
|
Primitives (Timeline) |
Functions
|
Scalar
|
Monadic
|
Conjugate ∙ Negate ∙ Signum ∙ Reciprocal ∙ Magnitude ∙ Exponential ∙ Natural Logarithm ∙ Floor ∙ Ceiling ∙ Factorial ∙ Not ∙ Pi Times ∙ Roll ∙ Type ∙ Imaginary ∙ Square Root ∙ Round
|
Dyadic
|
Add ∙ Subtract ∙ Times ∙ Divide ∙ Residue ∙ Power ∙ Logarithm ∙ Minimum ∙ Maximum ∙ Binomial ∙ Comparison functions ∙ Boolean functions (And, Or, Nand, Nor) ∙ GCD ∙ LCM ∙ Circular ∙ Complex ∙ Root
|
Non-Scalar
|
Structural
|
Shape ∙ Reshape ∙ Tally ∙ Depth ∙ Ravel ∙ Enlist ∙ Table ∙ Catenate ∙ Reverse ∙ Rotate ∙ Transpose ∙ Raze ∙ Mix ∙ Split ∙ Enclose ∙ Nest ∙ Cut (K) ∙ Pair ∙ Link ∙ Partitioned Enclose ∙ Partition
|
Selection
|
First ∙ Pick ∙ Take ∙ Drop ∙ Unique ∙ Identity ∙ Stop ∙ Select ∙ Replicate ∙ Expand ∙ Set functions (Intersection ∙ Union ∙ Without) ∙ Bracket indexing ∙ Index ∙ Cartesian Product ∙ Sort
|
Selector
|
Index generator ∙ Grade ∙ Index Of ∙ Interval Index ∙ Indices ∙ Deal ∙ Prefix and suffix vectors
|
Computational
|
Match ∙ Not Match ∙ Membership ∙ Find ∙ Nub Sieve ∙ Encode ∙ Decode ∙ Matrix Inverse ∙ Matrix Divide ∙ Format ∙ Execute ∙ Materialise ∙ Range
|
Operators |
Monadic
|
Each ∙ Commute ∙ Constant ∙ Replicate ∙ Expand ∙ Reduce ∙ Windowed Reduce ∙ Scan ∙ Outer Product ∙ Key ∙ I-Beam ∙ Spawn ∙ Function axis ∙ Identity (Null, Ident)
|
Dyadic
|
Bind ∙ Compositions (Compose, Reverse Compose, Beside, Withe, Atop, Over) ∙ Inner Product ∙ Determinant ∙ Power ∙ At ∙ Under ∙ Rank ∙ Depth ∙ Variant ∙ Stencil ∙ Cut ∙ Direct definition (operator) ∙ Identity (Lev, Dex)
|
Quad names
|
Index origin ∙ Comparison tolerance ∙ Migration level ∙ Atomic vector
|