Topic: APLX Help : Help on APL language : APL Primitives : ∘ Outer product
[ Previous | Next | Contents | Index | APL Home ]

www.microapl.co.uk

∘. Outer product


This involves two data items and a function. The function can be any dyadic function, including user-defined functions. The function operates on pairs of elements, one taken from the left argument and one from the right, till every possible combination of two elements has been used.

             X ← 2 3 4
             Y ← 1 2 3 4
             X ∘.× Y                 (Multiplies every number in X by every
      2  4  6  8                      number in Y generating a multiplication
      3  6  9 12                      table:
      4  8 12 16                                 Y
                                       |  1    2    3    4
                                  X   2|  2    4    6    8
                                      3|  3    6    9   12
                                      4|  4    8   12   16
             0 1 2 3 4 ∘.! 0 1 2 3 4
       1 1 1 1 1
       0 1 2 3 4                     (Gives all possible combinations. See !)
       0 0 1 3 6
       0 0 0 1 4
       0 0 0 0 1

Note that this function always generates a result of one more dimension than the original arguments. Two vectors, for example, generate a matrix.

             1 2∘.,⍳3                (Combines each element of the left argument
          1 1  1 2 1 3                with successive elements of the right
          2 1  2 2 2 3                argument using the , function)
             ⍴1 2∘.,⍳3
       2 3                           (Shape of result 2 3)
             2 3∘.↑1 2               (The ↑, 'take', function is applied using
            1 0   2 0                 successive elements of the left argument
          1 0 0 2 0 0                 and right argument)
             ⍴2 3∘.↑1 2
       2 2                           (Shape of result 2 2)

The Outer Product will accept arguments of any shape and number of dimensions. The result will be an array whose shape is the shape of the left argument followed by the shape of the right argument. For example:

             A ∘.× B

where A is a matrix of 4 rows and 3 columns, and B is a matrix of 5 rows and 2 columns, will produce a result of shape 4 3 5 2 - a four dimensional array.

The result is as defined above, namely all possible combinations of the left and right arguments. The rule that shows the layout of the result is that, for

             R←A ∘.<FUNCTION> B      (where A and B are shaped as above)

The result, R, has a shape 4 3 5 2 and

             R[C;D;E;F]  is given by    A[C;D] <FUNCTION> B[E;F]

Topic: APLX Help : Help on APL language : APL Primitives : ∘ Outer product
[ Previous | Next | Contents | Index | APL Home ]