From: Difference between revisions

From APL Wiki
Jump to navigation Jump to search
No edit summary
Line 1: Line 1:
{{Built-in|Select|⊇}} (jokingly referred to as ''Sane Indexing'') is a [[primitive function]] that allows selecting multiple [[major cell]]s using indices of the cells. It is equivalent to <source lang=apl inline>⌷⍨∘⊂⍨</source> and <source lang=apl inline>⌷⍤0 ∞</source>, only providing a neater notation for such a fundamental concept. It was introduced in [[Extended Dyalog APL]], and then adopted into [[dzaima/APL]].
{{Built-in|Select|⊇}} (jokingly referred to as ''Sane Indexing'') is a [[primitive function]] that allows selecting multiple [[major cell]]s using indices of the cells. It is equivalent to <source lang=apl inline>⌷⍨∘⊂⍨</source> and <source lang=apl inline>⌷⍤0 ∞</source>, 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 ==
== Common usage ==

Revision as of 15:54, 19 December 2020

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 ConjugateNegateSignumReciprocalMagnitudeExponentialNatural LogarithmFloorCeilingFactorialNotPi TimesRollTypeImaginarySquare Root
Dyadic AddSubtractTimesDivideResiduePowerLogarithmMinimumMaximumBinomialComparison functionsBoolean functions (And, Or, Nand, Nor) ∙ GCDLCMCircularComplexRoot
Non-Scalar
Structural ShapeReshapeTallyDepthRavelEnlistTableCatenateReverseRotateTransposeRazeMixSplitEncloseNestCut (K)PairLinkPartitioned EnclosePartition
Selection FirstPickTakeDropUniqueIdentityStopSelectReplicateExpandSet functions (IntersectionUnionWithout) ∙ Bracket indexingIndexCartesian ProductSort
Selector Index generatorGradeIndex OfInterval IndexIndicesDealPrefix and suffix vectors
Computational MatchNot MatchMembershipFindNub SieveEncodeDecodeMatrix InverseMatrix DivideFormatExecuteMaterialiseRange
Operators Monadic EachCommuteConstantReplicateExpandReduceWindowed ReduceScanOuter ProductKeyI-BeamSpawnFunction axis
Dyadic BindCompositions (Compose, Reverse Compose, Beside, Withe, Atop, Over) ∙ Inner ProductDeterminantPowerAtUnderRankDepthVariantStencilCutDirect definition (operator)
Quad names Index originComparison toleranceMigration levelAtomic vector