Understanding the Hadamard product calculator — concept and principle
This calculator multiplies two matrices of the same size entry by entry, the Hadamard (or Schur) product A ∘ B. It also gives the sum of all entries, which equals the Frobenius inner product ⟨A, B⟩ = trace(AᵀB), and the size. Use it in linear algebra, statistics, image processing and machine learning, where elementwise operations are common.
How it is calculated
(A ∘ B)_ij = a_ij × b_ij
Sum of all entries = Σ a_ij b_ij = ⟨A, B⟩ = trace(AᵀB)
- A and B must have exactly the same number of rows and columns.
The principle
Unlike ordinary matrix multiplication, which combines rows with columns, the Hadamard product simply pairs each entry with the one in the same position. That makes it commutative and associative, with the all-ones matrix as its identity. It is used whenever one grid of numbers scales another position by position, such as applying a mask to an image or weights to a table. Summing the products gives the Frobenius inner product, the matrix version of the dot product.
Worked example
Default inputs: A = [1 2 3; 4 5 6], B = [7 8 9; 10 11 12].
- Row 1: 1 × 7 = 7, 2 × 8 = 16, 3 × 9 = 27.
- Row 2: 4 × 10 = 40, 5 × 11 = 55, 6 × 12 = 72.
- A ∘ B = [7 16 27; 40 55 72], size 2 × 3.
- Sum of all entries = 7 + 16 + 27 + 40 + 55 + 72 = 217 = ⟨A, B⟩ = trace(AᵀB).
How to read the result
Each entry of the result depends only on the matching entries of A and B. The total, 217, is a single number measuring how A and B "line up": dividing it by the Frobenius norms of A and B would give a cosine similarity between the two matrices.
Common mistakes
- Confusing A ∘ B with the matrix product AB; here AB is not even defined for two 2 × 3 matrices.
- Trying to multiply matrices of different shapes.
- Expecting the identity matrix to be the identity for ∘; it is the all-ones matrix.
- Forgetting that the Frobenius inner product is a sum, not a matrix.
Frequently asked questions
What is the Hadamard product?
Entry-by-entry multiplication of two matrices of the same size.
Is it commutative?
Yes, A ∘ B = B ∘ A, unlike the ordinary matrix product.
What is the Frobenius inner product?
The sum of all entries of A ∘ B, equal to trace(AᵀB).
Sources: E. W. Weisstein, "Hadamard Product", Wolfram MathWorld