Back

πŸ“˜ Hadamard Product

βœ… Definition

If (x,y∈Rn),( \mathbf{x}, \mathbf{y} \in \mathbb{R}^n ), then the Hadamard product (element-wise product) is defined as:

[xβŠ™y][\mathbf{x} \odot \mathbf{y}]

πŸ‘‰ Correction/Addition:

The Hadamard product multiplies corresponding elements of the vectors (element-wise multiplication).


βœ… Example

x=[12],y=[45]xβŠ™y=[12]βŠ™[45]=[1Γ—42Γ—5]=[410]\begin{aligned} \mathbf{x} &= \begin{bmatrix} 1 \\ 2 \end{bmatrix}, \quad \mathbf{y} = \begin{bmatrix} 4 \\ 5 \end{bmatrix} \\[1.5em] \mathbf{x} \odot \mathbf{y} &= \begin{bmatrix} 1 \\ 2 \end{bmatrix} \odot \begin{bmatrix} 4 \\ 5 \end{bmatrix} = \begin{bmatrix} 1 \times 4 \\ 2 \times 5 \end{bmatrix} = \begin{bmatrix} 4 \\ 10 \end{bmatrix} \end{aligned}

❌ Condition

πŸ‘‰ Correct (clarified):

We cannot apply the Hadamard product if vectors have different dimensions.

x1=[1234],x2=[15300]\begin{gather} \mathbf{x_1} = \begin{bmatrix} 1 \\ 2 \\ 3 \\ 4 \end{bmatrix}, \qquad \mathbf{x_2} = \begin{bmatrix} 1 \\ 5 \\ 3 \\ 0 \\ 0 \end{bmatrix} \end{gather}

πŸ‘‰ Dimensions are different β†’ Not defined


πŸ“˜ Dot Product

βœ… Definition

If ( x,y∈Rn\mathbf{x}, \mathbf{y} \in \mathbb{R}^n ), then the dot product is:

xTy\mathbf{x}^T \mathbf{y}

πŸ‘‰ Addition:

  • The result is a scalar (single number)
  • It is also called the inner product

Example 1

x=[12],y=[45]\begin{align} \mathbf{x}= \begin{bmatrix} 1 \\ 2 \end{bmatrix}, \qquad \mathbf{y}= \begin{bmatrix} 4 \\ 5 \end{bmatrix} \\ \end{align} xTy=[12]\mathbf{x}^T \mathbf{y} = \begin{bmatrix}1 & 2\end{bmatrix} xTy=1Γ—4+2Γ—5=14\mathbf{x}^T\mathbf{y}=1Γ—4+2Γ—5=14

Example 2

[123479][110000]Β β€…β€ŠβŸΉβ€…β€Š=1Γ—1+2Γ—1+3Γ—0+4Γ—0+7Γ—0+9Γ—0=3\begin{align} \begin{bmatrix}1 & 2 & 3 & 4 & 7 & 9\end{bmatrix} \quad \begin{bmatrix}1 \\ 1 \\ 0 \\ 0 \\ 0 \\ 0\end{bmatrix} \ \implies \\ =1Γ—1+2Γ—1+3Γ—0+4Γ—0+7Γ—0+9Γ—0=3 \end{align}

πŸ“˜ Matrix Multiplication

⚠️ Important Rule (Added)

πŸ‘‰ Matrix multiplication is only possible when:

(columnsΒ ofΒ A)=(rowsΒ ofΒ B)(\text{columns of A}) = (\text{rows of B}) AΒ (4Γ—5)\mathbf{A} \ (4 \times 5)

πŸ“˜ General Formula of Matrix Multiplication

πŸ‘‰ Improved Explanation:

C=ABC = AB

Each element is:

cij=(rowΒ iΒ ofΒ A)β‹…(columnΒ jΒ ofΒ B)c_{ij} = \text{(row i of A)} \cdot \text{(column j of B)}

πŸ‘‰ Addition:

Each entry is a dot product of a row and a column.


πŸ“˜ Practice Problems


βœ… Practice 1 (Correct)

[12][56][561012]\begin{bmatrix}1 \\ 2 \end{bmatrix}\begin{bmatrix}5 & 6\end{bmatrix}\begin{bmatrix}5 & 6 \\ 10 & 12\end{bmatrix}

πŸ‘‰ Addition:

This is called an outer product.


❌ Practice 2 (Checked & Corrected Explanation)

[130241][520311010311]=[85061411111]\begin{bmatrix} 1 & 3 & 0 \\ 2 & 4 & 1 \end{bmatrix} \begin{bmatrix} 5 & 2 & 0 & 3 \\ 1 & 1 & 0 & 1 \\ 0 & 3 & 1 & 1 \end{bmatrix} = \begin{bmatrix} 8 & 5 & 0 & 6 \\ 14 & 11 & 1 & 11 \end{bmatrix}

πŸ‘‰ Addition:

Each entry is computed using row Γ— column dot product.


βœ… Practice 3 (Correct)

[123][56][5610121518]\begin{bmatrix}1 \\ 2 \\ 3\end{bmatrix}\begin{bmatrix}5 & 6\end{bmatrix} \begin{bmatrix} 5 & 6 \\ 10 & 12 \\ 15 & 18 \end{bmatrix}

πŸ‘‰ Addition:

Another example of an outer product.


⭐ Final Summary (Added for Study)

πŸ”Ή Hadamard Product

  • Element-wise multiplication
  • Same dimensions required
  • Output: vector

πŸ”Ή Dot Product

  • Multiply + sum
  • Output: scalar
  • Requires same dimension

πŸ”Ή Matrix Multiplication

  • Row Γ— Column
  • Inner dimensions must match
  • Output size: (mΓ—n)(nΓ—p)=(mΓ—p)(m \times n)(n \times p) = (m \times p)