Hadamard Product Calculator
Calculate the Hadamard product, also called the entrywise or element-wise product, of two matrices. Each resulting entry is obtained by multiplying the corresponding entries of the input matrices, which must have identical dimensions.
A
B
Learn About Hadamard Matrix Product
Definition and Element-Wise Multiplication
The Hadamard product (also known as the element-wise product or Schur product), denoted $\mathbf{A} \circ \mathbf{B}$ or $\mathbf{A} \odot \mathbf{B}$, is the operation of multiplying corresponding entries of two matrices sharing identical dimensions. If $\mathbf{A} = [a_{ij}]$ and $\mathbf{B} = [b_{ij}]$ are both $m \times n$ matrices, their Hadamard product $\mathbf{C} = \mathbf{A} \circ \mathbf{B}$ is an $m \times n$ matrix defined by:
Hadamard vs. Conventional Matrix Multiplication
A frequent point of student confusion is conflating the Hadamard product with standard matrix multiplication ($\mathbf{A}\mathbf{B}$):
- Hadamard Product ($\mathbf{A} \circ \mathbf{B}$): Multiplies entry-by-entry ($a_{ij} b_{ij}$). Requires identical dimensions ($m \times n$ and $m \times n$).
- Matrix Multiplication ($\mathbf{A}\mathbf{B}$): Computes row-by-column dot products ($\sum_{k} a_{ik} b_{kj}$). Requires inner dimensions to match ($m \times p$ and $p \times n$).
Fundamental Algebraic Properties
Because it operates element-wise, the Hadamard product inherits the abelian properties of scalar multiplication:
- Commutativity: $\mathbf{A} \circ \mathbf{B} = \mathbf{B} \circ \mathbf{A}$ (strictly unlike standard matrix multiplication!)
- Associativity: $(\mathbf{A} \circ \mathbf{B}) \circ \mathbf{C} = \mathbf{A} \circ (\mathbf{B} \circ \mathbf{C})$
- Distributivity over Addition: $\mathbf{A} \circ (\mathbf{B} + \mathbf{C}) = \mathbf{A} \circ \mathbf{B} + \mathbf{A} \circ \mathbf{C}$
- Identity Element: The identity matrix under the Hadamard product is the matrix of all ones $\mathbf{J}_{m \times n}$:
- Zero Annihilator: $\mathbf{A} \circ \mathbf{0} = \mathbf{0}$
- Transpose Distribution: $(\mathbf{A} \circ \mathbf{B})^T = \mathbf{A}^T \circ \mathbf{B}^T$
The Schur Product Theorem
A celebrated theoretical result is the Schur Product Theorem:
If $\mathbf{A}$ and $\mathbf{B}$ are both $n \times n$ positive semi-definite matrices, their Hadamard product $\mathbf{A} \circ \mathbf{B}$ is also positive semi-definite.
Furthermore, if both matrices are strictly positive definite, $\mathbf{A} \circ \mathbf{B}$ is strictly positive definite.
Worked Numerical Example
Given matrices $\mathbf{A}, \mathbf{B} \in \mathbb{R}^{2 \times 3}$:
Multiply corresponding entries:
1. When do I use the Hadamard product instead of standard matrix multiplication?
Use standard matrix multiplication ($\mathbf{A}\mathbf{B}$) when modeling compositions of linear transformations, coordinate projections, or systems of equations. Use the Hadamard product ($\mathbf{A} \circ \mathbf{B}$) when applying masks, point-wise attenuation, audio signal modulation, or element-wise weights in deep learning.
2. Can two matrices of different dimensions have a Hadamard product?
No. Every entry $a_{ij}$ must have an exact corresponding entry $b_{ij}$. If dimensions differ, the Hadamard product is mathematically undefined.
3. What is the Hadamard inverse of a matrix?
The Hadamard inverse $\mathbf{A}^{\circ -1}$ exists if and only if no entry of $\mathbf{A}$ is zero. Each entry is the scalar reciprocal of the corresponding matrix entry: $[\mathbf{A}^{\circ -1}]_{ij} = \frac{1}{a_{ij}}$, satisfying $\mathbf{A} \circ \mathbf{A}^{\circ -1} = \mathbf{J}$.
1. Neural Networks and Attention Gating
In deep learning, the Hadamard product is ubiquitous. In Long Short-Term Memory (LSTM) and Gated Recurrent Unit (GRU) networks, forget gates and update gates use Hadamard multiplication ($\mathbf{f}_t \circ \mathbf{c}_{t-1}$) to selectively retain or suppress information across sequence steps. Similarly, dropout regularization applies a random binary mask to activations via Hadamard multiplication.
2. Hadamard Matrices vs. Hadamard Product
Do not confuse the Hadamard product with a Hadamard matrix. A Hadamard matrix is a square matrix $\mathbf{H}$ with entries $\pm 1$ whose columns are mutually orthogonal ($\mathbf{H}^T\mathbf{H} = n\mathbf{I}$). Both are named after French mathematician Jacques Hadamard, but denote completely different concepts.