Inner Product

From APL Wiki
Revision as of 05:59, 6 September 2021 by Adám Brudzewsky (talk | contribs)
Jump to navigation Jump to search
.

Inner Product (.), is a dyadic operator, which will produce a dyadic function when applied with two dyadic functions. In APL, the inner product is a generalisation of the matrix product, which allows not only addition-multiplication, but any dyadic functions given.

Examples

      x ← 1 2 3
      y ← 4 5 6
      x ,.(⊂,) y ⍝ visualizing of pairing
┌─────────────┐
│┌───┬───┬───┐│
││1 4│2 5│3 6││
│└───┴───┴───┘│
└─────────────┘
      x {⊂⍺,'+',⍵}.{⊂⍺,'×',⍵} y ⍝ visualizing function application in matrix multiplication
┌───────────────────────────┐
│┌─────────────────────────┐│
││┌─────┬─┬───────────────┐││
│││1 × 4│+│┌─────┬─┬─────┐│││
│││     │ ││2 × 5│+│3 × 6││││
│││     │ │└─────┴─┴─────┘│││
││└─────┴─┴───────────────┘││
│└─────────────────────────┘│
└───────────────────────────┘
      x+.×y ⍝ matrix multiplication
32

Note that the shapes of the arguments must be compatible with each other: The last axis of the left argument must have the same length as the first axis of the right argument, or formally, for X f.g Y it must be that (¯1↑⍴X)≡(1↑⍴Y). The shape of the result is (¯1↓⍴X),(1↓⍴Y).

For example, when applying inner product on two matrices, the number of columns in the left array must match with number of rows in the right array, otherwise we will get an error.

      ⎕  ← x ← 2 3⍴⍳10
1 2 3
4 5 6
      ⎕ ← y ← 4 2⍴⍳10
1 2
3 4
5 6
7 8
      x+.×y 
LENGTH ERROR
      x+.×y
        ∧
      ⎕ ← y ← 3 2⍴⍳10 ⍝ reshape y to be compatible with x
      x+.×y
22 28
49 64

External links

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