Shapes or index errors in NumPy
- Python
- NumPy
You may see
Why it happens
- Pixels are
img[y, x], notimg[x, y]. - Two pictures have different sizes or one is grey.
How to fix it
- Print both shapes.
- Use
cv2.resizeso the sizes match. - Use
img[y, x], but(x, y)for drawing.
It worked if: The shapes match.
Related errors
Tutorials where it can happen
Seen in a real run (some lines are close variants of it). Produced with Python 3.13 on Windows. With NumPy 2.2.6.
Didn't help? Search another error or ask us.

