Inner Product: Difference between revisions
No edit summary 
(Editing; contrast shape rules with conformability) 

Line 1:  Line 1:  
{{BuiltinInner Product<nowiki>.</nowiki>}}  {{BuiltinInner Product<nowiki>.</nowiki>}} is a [[dyadic operator]] that produces a [[dyadic function]] when applied with two dyadic functions. It's a generalisation of the [[wikipedia:Matrix multiplicationmatrix product]], allowing not just additionmultiplication, but any [[dyadic function]]s given as [[operand]]s.  
== Examples ==  == Examples ==  
Line 25:  Line 25:  
</source>  </source>  
The [[shape]]s 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 <source lang=apl inline>X f.g Y</source> it must be that <source lang=apl inline>(¯1↑⍴X)≡(1↑⍴Y)</source>. Although this rule differs from [[conformability]], the arguments may also be subject to [[scalar extensionscalar]] or [[singleton extension]]. The shape of the result is <source lang=apl inline>(¯1↓⍴X),(1↓⍴Y)</source>.  
For example, when applying inner product on two [[matrixmatrices]], the number of columns in the left array must match with number of rows in the right array, otherwise we will get an error.  For example, when applying inner product on two [[matrixmatrices]], the number of columns in the left array must match with number of rows in the right array, otherwise we will get an error. 
Revision as of 19:36, 6 September 2021
.

Inner Product (.
) is a dyadic operator that produces a dyadic function when applied with two dyadic functions. It's a generalisation of the matrix product, allowing not just additionmultiplication, but any dyadic functions given as operands.
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
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)
. Although this rule differs from conformability, the arguments may also be subject to scalar or singleton extension. 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