Concept Flow - outer() for outer operations
Input: Vector A
Input: Vector B
Compute outer product
Output: Matrix with shape (len(A), len(B))
The outer() function takes two vectors and computes all pairwise products, producing a matrix.
import numpy as np A = np.array([1, 2]) B = np.array([3, 4]) result = np.outer(A, B) print(result)
| Step | Operation | Input A | Input B | Result Matrix |
|---|---|---|---|---|
| 1 | Start with vectors | [1, 2] | [3, 4] | N/A |
| 2 | Multiply A[0] * B[0] | 1 | 3 | result[0,0] = 3 |
| 3 | Multiply A[0] * B[1] | 1 | 4 | result[0,1] = 4 |
| 4 | Multiply A[1] * B[0] | 2 | 3 | result[1,0] = 6 |
| 5 | Multiply A[1] * B[1] | 2 | 4 | result[1,1] = 8 |
| 6 | Final matrix | N/A | N/A | [[3, 4], [6, 8]] |
| Variable | Start | After Step 2 | After Step 3 | After Step 4 | After Step 5 | Final |
|---|---|---|---|---|---|---|
| A | [1, 2] | [1, 2] | [1, 2] | [1, 2] | [1, 2] | [1, 2] |
| B | [3, 4] | [3, 4] | [3, 4] | [3, 4] | [3, 4] | [3, 4] |
| result | empty | [[3, 0], [0, 0]] | [[3, 4], [0, 0]] | [[3, 4], [6, 0]] | [[3, 4], [6, 8]] | [[3, 4], [6, 8]] |
numpy.outer(a, b) - Takes two 1D arrays a and b - Returns matrix of shape (len(a), len(b)) - Each element is product of a[i] * b[j] - Useful for pairwise multiplication - Output is 2D array (outer product matrix)