ValueError: operands could not be broadcast together with shapes (3,) (4,)
Two NumPy arrays have shapes that can’t be combined element-wise.
Seen on:
Python
Meaning
Broadcasting aligns dimensions from the right; each pair must be equal or 1. Mismatched lengths, a missing axis or a transposed matrix cause it.
Common causes
- Arrays of different lengths
- Column vs row vector confusion
- Wrong axis after reshape/transpose
⚡ Quick fix
- Print .shape of both arrays
- Reshape with x[:, None] or x.reshape(-1, 1)
- Fix the data so lengths match
Detailed fix by platform
Python
a = a.reshape(-1, 1) # (3,) -> (3, 1) to broadcast against (1, 4)
How to diagnose
- Shapes — Which shapes are shown?
- Intent — Element-wise or matrix multiplication (@)?
🧠 Still stuck? Analyze your error
Paste the full message, response headers or stack trace — we'll detect the platform and point to the most likely cause.
Was this page helpful?
Report a correction or suggest an improvement
Last updated 2 Oct 2026