Expand

From APL Wiki
(Redirected from Expand First)
Jump to navigation Jump to search
\

Expand (\, ) is a dyadic function or monadic operator that copies each element of the right argument a given number of times and inserts prototype elements, ordering the copies along a specified axis. Typically \ is called Expand while is called "Expand First" or an equivalent.

Expand is usually associated with Replicate (/), and the two functions are related to Mesh and Mask. It shares a glyph with Scan even though Expand is naturally a function and Scan must be an operator. This incongruity is sometimes resolved by making Expand an operator itself, and sometimes by function-operator overloading allowing both syntactic elements to coexist.

Examples

For vector arguments, the number of positive values in the left argument must match the length of the right argument. Each positive value produces copies of the corresponding item on the right argument; a zero or negative value produces one or more prototype elements.

      1 0 3 ¯2 2\'abc'
a bbb  cc

For Boolean left argument, Expand is the right inverse of Replicate, as Expand inserts prototype elements at the exact places which Replicate will remove:

      1 0 0 1 0 1\'abc'
a  b c
      1 0 0 1 0 1/'a  b c'
abc

High-rank arrays

Expand works along a particular axis, which can be specified in languages with function axis and otherwise is the first axis for , and the last axis for \.

      A3 4⎕A
ABCD
EFGH
IJKL
      1 0 3 2 ¯2 1\A
A BBBCC  D
E FFFGG  H
I JJJKK  L
      3 1 ¯1 2A
ABCD
ABCD
ABCD
EFGH
    
IJKL
IJKL

Some implementations allow the right argument to have length 1 along the expansion axis even if other axes have lengths not equal to 1.

      1 ¯2 3 \ 'abc'
a  aaa
b  bbb
c  ccc

External Links

Lessons

Documentation


APL built-ins [edit]
Primitive functions
Scalar
Monadic ConjugateNegateSignumReciprocalMagnitudeExponentialNatural LogarithmFloorCeilingFactorialNotPi TimesRollTypeImaginarySquare Root
Dyadic AddSubtractTimesDivideResiduePowerLogarithmMinimumMaximumBinomialComparison functionsBoolean functions (And, Or, Nand, Nor) ∙ GCDLCMCircularComplexRoot
Non-Scalar
Structural ShapeReshapeTallyDepthRavelEnlistTableCatenateReverseRotateTransposeRazeMixSplitEncloseNestCut (K)PairLinkPartitioned EnclosePartition
Selection FirstPickTakeDropUniqueIdentitySelectReplicateExpandSet functions (IntersectionUnionWithout) ∙ Bracket indexingIndex
Selector Index generatorGradeIndex OfInterval IndexIndicesDeal
Computational MatchNot MatchMembershipFindNub SieveEncodeDecodeMatrix InverseMatrix DivideFormatExecuteMaterialiseRange
Primitive operators Monadic EachCommuteConstantReplicateExpandReduceWindowed ReduceScanOuter ProductKeyI-beamSpawnFunction axis
Dyadic BindCompositions (Compose, Reverse Compose, Beside, Atop, Over) ∙ Inner ProductPowerAtUnderRankDepthVariantStencilCut (J)
Quad names
Arrays Index originMigration levelAtomic vector
Functions Case convertUnicode convert
Operators SearchReplace