You can learn more about the outer product in the resource below:
The outer product can be expressed as shown:
Suppose you have two vectors a and b with the values as shown:
a = [a0, a1, a2…aM]
b = [b0, b1, b2…bN]
The outer product is calculated as shown:
Let us learn how to use the outer() function in NumPy.
The function syntax can be expressed as shown in the code snippet below:
The function has a simple syntax and accepts three main parameters:
- a – refers to the first input vector. Think of it as M in the previous explanation.
- b – refers to the second input vector. In this case, it acts as N.
- out – an alternative array to store the resulting output. It takes shape (M, N).
The function returns the outer product of the two vectors in the for:
The code below shows how to calculate the outer product of two one-dimensional arrays.
The resulting array is as shown:
In the case of a 2×3 matrix, the function should return:
The function should return:
The outer function also allows you to perform the outer product with a vector of letters.
An example is as shown:
The code above should return:
This article guides you in calculating the outer products of two vectors using NumPy’s outer() function.
Thanks for reading & Happy coding!!