In the realm of linear algebra, the dot product (also known as the inner product or scalar product) is a fundamental operation that quantifies the similarity or relationship between two vectors. It plays a crucial role in various mathematical and computational applications, especially in the field of deep learning.
The dot product of two vectors, denoted as $\mathbf{A} \cdot \mathbf{B}$ or simply $\langle \mathbf{A}, \mathbf{B} \rangle$, is a scalar value obtained by multiplying the corresponding components of the vectors and summing up the results. Mathematically, for two vectors $\mathbf{A}$ and $\mathbf{B}$ with dimensions $n$, the dot product is calculated as:
$$\mathbf{A} \cdot \mathbf{B} = \sum_{i=1}^{n} A_i \cdot B_i$$
Here, $A_i$ and $B_i$ represent the components of vectors $\mathbf{A}$ and $\mathbf{B}$, respectively.
Let’s consider two vectors:
$\mathbf{A} = [2, 3, -1]$
$\mathbf{B} = [1, -2, 4]$
To compute their dot product, we follow the formula:
$$\mathbf{A} \cdot \mathbf{B} = (2 \cdot 1) + (3 \cdot -2) + (-1 \cdot 4) = 2 – 6 – 4 = -8$$
So, $\langle \mathbf{A}, \mathbf{B} \rangle = -8$
You can calculate the dot product of two vectors using Python and NumPy. Here’s an example code snippet:
import numpy as np
# Define the vectors
A = np.array([2, 3, -1])
B = np.array([1, -2, 4])
# Calculate the dot product
dot_product = np.dot(A, B)
# Display the result
print("Dot Product of A and B:", dot_product)In this code, we first import NumPy, create two NumPy arrays A and B to represent our vectors, and then use np.dot() to compute the dot product.