---
title: "Hadamard Product (Element-wise Op)"
description: "The Hadamard product multiplies matching entries and keeps the shape. Compare it with matrix multiplication, build a mask, and check NumPy's * and @."
canonical_url: "https://fanout.sh/ai/lessons/math-fundamentals-hadamard-product"
md_url: "https://fanout.sh/ai/lessons/math-fundamentals-hadamard-product.md"
access: "public"
---

# Hadamard Product (Element-wise Op)

The Hadamard product multiplies matching entries and keeps the shape. Compare it with matrix multiplication, build a mask, and check NumPy's * and @.

## Public overview

You have two arrays of the same shape. You want each number in the first array multiplied by the number in the matching position of the second.

That operation is the Hadamard product , also called elementwise multiplication. It preserves the shape:

The ⊙ symbol says “match positions.” The top-right entry is 2 × 6 = 12. It does not mix numbers from other positions.

Compare it with matrix multiplication

Using the same two arrays, matrix multiplication combines rows with columns:

Its top-right entry is 1 × 6 + 2 × 8 = 22. The shapes happen to match the first result, so checking shape alone would not catch confusing these operations.

Predict: To zero the second entry of [3, 7, 2] while preserving the others, what array would you multiply it by elementwise?

Inspect both in code

With NumPy installed, run:

python import numpy as np

a = np.array([[1, 2], [3, 4]]) b = np.array([[5, 6], [7, 8]]) print((a b).tolist()) [[5, 12], [21, 32]] print((a @ b).tolist()) [[19, 22], [43, 50]]

For NumPy arrays, is elementwise multiplication and @ is matrix multiplication. These meanings depend on the objects: ordinary Python lists do not support list-by-list elementwise multiplication. For example, [1, 2] 2 repeats the list instead.

---
This representation contains public Fanout content only. Protected Pro lessons, account data, billing, checkout, and pricing are not included.

Browse the public content map: https://fanout.sh/sitemap.md
