Skip to content

8. Hadamard Product

Updated
17 Sept 2026
2 min read
6 sections
Page 10 of 17
Master Linear Algebra with Python

Vector Hadamard Multiplication (Element-Wise)

If you were to ask someone on the street who had never studied linear algebra how to multiply two vectors together, they would likely describe Hadamard Multiplication. Also commonly known as element-wise multiplication, this operation is the most intuitive form of vector multiplication.

In this lesson, we define the Hadamard product, explore its geometric constraint, contrast it with the dot product, and implement it in Python.


1. Mathematical Definition

The Hadamard Product is defined as the multiplication of corresponding elements from two vectors of the same size.

Mathematically, we denote Hadamard multiplication using the circle-dot operator ⊙\odot:

c=a⊙b\mathbf{c} = \mathbf{a} \odot \mathbf{b}

For two vectors a,b∈Rn\mathbf{a}, \mathbf{b} \in \mathbb{R}^n, the resulting vector c∈Rn\mathbf{c} \in \mathbb{R}^n is computed element-by-element:

ci=ai⋅bifor i=1,2,…,nc_i = a_i \cdot b_i \quad \text{for } i = 1, 2, \dots, n

Writing it out in vector form:

[a1a2⋮an]⊙[b1b2⋮bn]=[a1b1a2b2⋮anbn]\begin{bmatrix} a_1 \\ a_2 \\ \vdots \\ a_n \end{bmatrix} \odot \begin{bmatrix} b_1 \\ b_2 \\ \vdots \\ b_n \end{bmatrix} = \begin{bmatrix} a_1 b_1 \\ a_2 b_2 \\ \vdots \\ a_n b_n \end{bmatrix}

2. The Dimensionality Constraint

Hadamard multiplication has a strict geometric constraint: it is defined only for vectors of the exact same size.

  • Valid: Multiplying two 3-dimensional vectors.
  • Invalid: Multiplying a 3-dimensional vector and a 5-dimensional vector.

If the vectors have different shapes, their element-wise corresponding parts do not exist, and the operation is mathematically undefined.


3. Step-by-Step Example

Let's compute the Hadamard product of two vectors w1\mathbf{w}_1 and w2\mathbf{w}_2 in R3\mathbb{R}^3:

w1=[135],w2=[342]\mathbf{w}_1 = \begin{bmatrix} 1 \\ 3 \\ 5 \end{bmatrix}, \quad \mathbf{w}_2 = \begin{bmatrix} 3 \\ 4 \\ 2 \end{bmatrix}

Multiply the corresponding elements: w1⊙w2=[1⋅33⋅45⋅2]=[31210]\mathbf{w}_1 \odot \mathbf{w}_2 = \begin{bmatrix} 1 \cdot 3 \\ 3 \cdot 4 \\ 5 \cdot 2 \end{bmatrix} = \begin{bmatrix} 3 \\ 12 \\ 10 \end{bmatrix}


4. Hadamard Product vs. Dot Product

It is crucial not to confuse Hadamard multiplication with the Vector Dot Product:

FeatureHadamard Product (a⊙b\mathbf{a} \odot \mathbf{b})Dot Product (aTb\mathbf{a}^{\text{T}}\mathbf{b})
Output TypeVector (same size as inputs)Scalar (a single number)
SummationNo summationSums the products of elements
NotationCircle-dot (⊙\odot)Transpose matrix multiplication or dot (⋅\cdot)
Core ConceptComponent scaling / MaskingSpatial projection / Similarity

If we took the dot product of the example vectors above, we would sum the Hadamard results: w1Tw2=3+12+10=25\mathbf{w}_1^{\text{T}}\mathbf{w}_2 = 3 + 12 + 10 = 25


5. Python Implementation

In Python, NumPy provides two primary ways to compute the Hadamard product:

Method 1: Using np.multiply()

The np.multiply() function accepts standard Python lists or arrays and computes their element-wise product:

python
import numpy as np

# Define lists
w1 = [ 1, 3, 5 ]
w2 = [ 3, 4, 2 ]

# Compute Hadamard multiplication
w3 = np.multiply(w1, w2)
print(w3)
Out · stdout
[ 3 12 10]

Method 2: Using the Overloaded * Operator

When you convert lists to NumPy arrays, the standard multiplication asterisk operator * is overloaded to perform element-wise (Hadamard) multiplication automatically:

python
import numpy as np

# Convert to NumPy arrays
arr1 = np.array([ 1, 3, 5 ])
arr2 = np.array([ 3, 4, 2 ])

# Compute using overloaded * operator
w3 = arr1 * arr2
print(w3)
Out · stdout
[ 3 12 10]
Avoid the * Operator on Lists: Do not use the standard * operator on raw Python lists (e.g. w1 * w2). Python will throw a TypeError because it interprets list multiplication as duplication, which is invalid between two lists. Always convert to NumPy arrays first or use np.multiply().

Key Takeaways

  • Hadamard Product: Element-wise multiplication, yielding a vector of the same size.
  • Symbol: Denoted by the circle-dot operator ⊙\odot.
  • Constraint: Valid only for vectors of identical dimensions.
  • Python Syntax: Use np.multiply(a, b) or convert to arrays and multiply with a * b.