Rank (operator): Difference between revisions

From APL Wiki
Jump to navigation Jump to search
(Created page with "Rank (<source lang=apl inline>⍤</source>) is a primitive dyadic operator which applies its left operand function to cells of its arguments...")
 
No edit summary
Line 1: Line 1:
:''This article is about the operator. See [[Rank]] for the number associated with every array. For numbers associated with a function specifying its argument rank, see [[function rank]].''
Rank (<source lang=apl inline>⍤</source>) is a [[primitive operator|primitive]] [[dyadic operator]] which applies its left [[operand]] function to [[cells]] of its arguments specified by its right operand array.  
Rank (<source lang=apl inline>⍤</source>) is a [[primitive operator|primitive]] [[dyadic operator]] which applies its left [[operand]] function to [[cells]] of its arguments specified by its right operand array.  



Revision as of 15:16, 5 October 2020

This article is about the operator. See Rank for the number associated with every array. For numbers associated with a function specifying its argument rank, see function rank.

Rank () is a primitive dyadic operator which applies its left operand function to cells of its arguments specified by its right operand array.

Rank specification

The right operand specifies the rank of subarrays to which the left operand function is applied as follows: For left argument and right argument ,

   ⍤    c   ⍝ Rank-c cells of ⍵ (monadic) or both arguments (dyadic)
   ⍤  b c   ⍝ Rank-b cells of ⍺ and rank-c cells of ⍵ (dyadic)
   ⍤a b c   ⍝ Rank-a cells of ⍵ (monadic), b-cells of ⍺ and c-cells of ⍵ (dyadic)

A non-negative right operand specifies the number of final axes to which the function applies. A negative right operand specifies complementary rank, i.e. the number of leading axes to be excluded. Negative rank can also be thought of as rank specification relative to the overall rank of the argument array.

Since a rank specification greater than the rank of the argument array means to apply the function to the whole array, 99, (⌊/⍬) or , depending on the implementation, is "rank infinity" and always specifies the whole argument array.

Examples

Rotate rows in matrices of a 3D array:

      ⊖⍤2⊢3 2 4⍴⎕A
EFGH
ABCD
    
MNOP
IJKL
    
UVWX
QRST

Laminate scalars from arrays of differing ranks:

      'ABCD',⍤0⍤1⊢2 4⍴⍳8
A 1
B 2
C 3
D 4
   
A 5
B 6
C 7
D 8

Flat outer product:

      -⍤1⍤1 99⍨3 2⍴6 7 1 1 2 4   ⍝ ↑∘.-⍨↓
 0  0
 5  6
 4  3
     
¯5 ¯6
 0  0
¯1 ¯3
     
¯4 ¯3
 1  3
 0  0

History

The rank operator was invented by Arthur Whitney in 1982 and first implemented in SHARP APL in 1983. It has been described as "a microcosm of APL history"[1], its evolution a progression from scalar extension, which has been in APL since its inception, through leading axis theory to a construct which is a generalisation of scalar extension, inner (matrix) product, outer product, maplist in LISP, map in modern functional programming languages and the broadcast facility in NumPy.

External links

Documentation

Publications


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