Partitioned Enclose: Difference between revisions

From APL Wiki
Jump to navigation Jump to search
No edit summary
mNo edit summary
Line 1: Line 1:
{{Built-in|Partitioned Enclose|⊂}} is a [[dyadic function]] which splits its right argument into differently sized pieces as determined by the left argument.
{{Built-in|Partitioned Enclose|⊂}} is a [[dyadic function]] which splits its right argument into differently sized pieces as determined by the left argument.


In the simplest case, and on a vector right argument, the corresponding element in the left argument indicates where <ref group=note name=max></ref> '''divisions''' begin:
In the simplest case, and on a vector right argument, the corresponding element in the left argument indicates where '''divisions''' begin:
<source lang=apl>
<source lang=apl>
       1 0 1 0 0 0 0⊂'HiEarth'
       1 0 1 0 0 0 0⊂'HiEarth'

Revision as of 13:00, 27 January 2020

Partitioned Enclose () is a dyadic function which splits its right argument into differently sized pieces as determined by the left argument.

In the simplest case, and on a vector right argument, the corresponding element in the left argument indicates where divisions begin:

      1 0 1 0 0 0 0⊂'HiEarth'
┌──┬─────┐
│Hi│Earth│
└──┴─────┘
Works in: Dyalog APL

Almost all dialects restrict the left argument to provide only this functionality. However, the left argument can be interpreted as a count of how many partitions begin with a particular position:

      2 0 3 0 0 0 0⊂'HiEarth'
┌┬──┬┬┬─────┐
││Hi│││Earth│
└┴──┴┴┴─────┘

Additional trailing empty divisions are thus created by adding an additional division count corresponding to the index beyond the end of the right argument[note 1]:

      1 0 1 0 0 0 0 1⊂'HiEarth'
┌──┬─────┬┐
│Hi│Earth││
└──┴─────┴┘

This interpretation allows a simple definition of a split-into-lengths function:

Try it online!

      Split←{⍵ ⊂⍨ ⍸⍣¯1 +\ ¯1↓1,⍺}
      3 3 4 Split 'HowAreYou?'
┌───┬───┬────┐
│How│Are│You?│
└───┴───┴────┘

External links

Tutorials

Documentation

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


Cite error: <ref> tags exist for a group named "note", but no corresponding <references group="note"/> tag was found