Inner Product: Difference between revisions

Jump to navigation Jump to search
1,528 bytes added ,  05:59, 6 September 2021
no edit summary
No edit summary
Line 5: Line 5:
       x ← 1 2 3
       x ← 1 2 3
       y ← 4 5 6
       y ← 4 5 6
       x ,.(,) y ⍝ visualizing inner product
       x ,.(,) y ⍝ visualizing of pairing
┌─────────────┐
┌─────────────┐
│┌───┬───┬───┐│
│┌───┬───┬───┐│
Line 11: Line 11:
│└───┴───┴───┘│
│└───┴───┴───┘│
└─────────────┘
└─────────────┘
      x {⊂⍺,'+',⍵}.{⊂⍺,'×',⍵} y ⍝ visualizing function application in matrix multiplication
┌───────────────────────────┐
│┌─────────────────────────┐│
││┌─────┬─┬───────────────┐││
│││1 × 4│+│┌─────┬─┬─────┐│││
│││    │ ││2 × 5│+│3 × 6││││
│││    │ │└─────┴─┴─────┘│││
││└─────┴─┴───────────────┘││
│└─────────────────────────┘│
└───────────────────────────┘
       x+.×y ⍝ matrix multiplication
       x+.×y ⍝ matrix multiplication
32     
32     
</source>
</source>


Note that for inner product between N-dimensional arrays, their dimension must be compatible with each other.  
Note that 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>. The shape of the result is <source lang=apl inline>(¯1↓⍴X),(1↓⍴Y)</source>.


For example, when applying inner-product to a 2D array, the column count of the left array must match with the row count of the right array, otherwise we will get an error.
For example, when applying inner product on two [[matrix|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.
<source lang=apl>
<source lang=apl>
       ⎕  ← x ← 2 3⍴⍳10
       ⎕  ← x ← 2 3⍴⍳10
Line 26: Line 36:
3 4
3 4
5 6
5 6
7 8  
7 8
       x+.×y  
       x+.×y  
LENGTH ERROR
LENGTH ERROR
Line 36: Line 46:
49 64
49 64
</source>
</source>
== External links ==
=== Documentation ===
* [https://help.dyalog.com/latest/#Language/Primitive%20Operators/Inner%20Product.htm Dyalog]
* [https://microapl.com/apl_help/ch_020_020_880.htm APLX]
* J [https://www.jsoftware.com/help/dictionary/d300.htm Dictionary], [https://code.jsoftware.com/wiki/Vocabulary/dot#dyadic NuVoc]
{{APL built-ins}}[[Category:Primitive operators]]

Navigation menu