Group (K): Difference between revisions

From APL Wiki
Jump to navigation Jump to search
m (Marshall moved page Group to Group (K): Decided (with Adám) that K doesn't have a strong claim to be primary vs BQN)
(Fix explanation for why K3 group doesn't return a dictionary)
Line 1: Line 1:
:''This page is about the K primitive that returns a dictionary. For the primitive that returns an array introduced by BQN, see [[Group (BQN)]].''
:''This page is about the K primitive that returns a dictionary. For the primitive that returns an array introduced by BQN, see [[Group (BQN)]].''


{{Built-in|Group|<nowiki>=</nowiki>}} is a [[monadic function]] in [[K]] that returns a [[dictionary]] whose keys are the [[unique]] values in its argument and whose value for a given key is the list of indices where it appears. In versions before K4, which introduced dictionaries, Group returns only an array of the index lists, and the keys must be obtained separately.
{{Built-in|Group|<nowiki>=</nowiki>}} is a [[monadic function]] in [[K]] that returns a [[dictionary]] whose keys are the [[unique]] values in its argument and whose value for a given key is the list of indices where it appears. In versions before K4, which allowed dictionaries with arbitrary keys, Group returns only an array of the index lists, and the keys must be obtained separately.


Group can be seen as a simplified version of [[Key]], as it contains the same information as <syntaxhighlight lang=apl inline>{⍺⍵}⌸</syntaxhighlight>: the first result column is the dictionary keys and the second is its values. The [[BQN]] primitive also called [[Group (BQN)|Group]] can be described as a specialization of K's Group to arrays, where an array corresponds to a dictionary with natural numbers for its keys.<ref>[[Marshall Lochbaum]]. [https://mlochbaum.github.io/BQN/commentary/history.html#group BQN's development history: Group].</ref>
Group can be seen as a simplified version of [[Key]], as it contains the same information as <syntaxhighlight lang=apl inline>{⍺⍵}⌸</syntaxhighlight>: the first result column is the dictionary keys and the second is its values. The [[BQN]] primitive also called [[Group (BQN)|Group]] can be described as a specialization of K's Group to arrays, where an array corresponds to a dictionary with natural numbers for its keys.<ref>[[Marshall Lochbaum]]. [https://mlochbaum.github.io/BQN/commentary/history.html#group BQN's development history: Group].</ref>

Revision as of 01:57, 2 February 2024

This page is about the K primitive that returns a dictionary. For the primitive that returns an array introduced by BQN, see Group (BQN).
=

Group (=) is a monadic function in K that returns a dictionary whose keys are the unique values in its argument and whose value for a given key is the list of indices where it appears. In versions before K4, which allowed dictionaries with arbitrary keys, Group returns only an array of the index lists, and the keys must be obtained separately.

Group can be seen as a simplified version of Key, as it contains the same information as {⍺⍵}⌸: the first result column is the dictionary keys and the second is its values. The BQN primitive also called Group can be described as a specialization of K's Group to arrays, where an array corresponds to a dictionary with natural numbers for its keys.[1]

External links

References

APL built-ins [edit]
Primitives (Timeline) Functions
Scalar
Monadic ConjugateNegateSignumReciprocalMagnitudeExponentialNatural LogarithmFloorCeilingFactorialNotPi TimesRollTypeImaginarySquare RootRound
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 axisIdentity (Null, Ident)
Dyadic BindCompositions (Compose, Reverse Compose, Beside, Withe, Atop, Over) ∙ Inner ProductDeterminantPowerAtUnderRankDepthVariantStencilCutDirect definition (operator)Identity (Lev, Dex)
Quad names Index originComparison toleranceMigration levelAtomic vector