Outer Product: Difference between revisions

Jump to navigation Jump to search
167 bytes removed ,  09:29, 5 September 2021
m
remove duplicated code
m (Added prime number example)
m (remove duplicated code)
Line 32: Line 32:
For example, suppose we want to find duplicated elements in an non-[[nested array]]. Intuitively speaking, the easiest way to solve this problem is to compare each element of the array with all other elements, which is exactly what an outer product does.
For example, suppose we want to find duplicated elements in an non-[[nested array]]. Intuitively speaking, the easiest way to solve this problem is to compare each element of the array with all other elements, which is exactly what an outer product does.
<source lang=apl>
<source lang=apl>
      x ← 1 2 3 2
      matrix ← x∘.=x ⍝ compare elements with each other using equal
      count ← +/matrix ⍝ get the number of occurence of each element
       x ← 1 2 3 2
       x ← 1 2 3 2
       ⎕ ← matrix ← x∘.=x ⍝ compare elements with each other using equal
       ⎕ ← matrix ← x∘.=x ⍝ compare elements with each other using equal
24

edits

Navigation menu