#1 India's Top IT Training Institute

×

About Uncodemy

Know more about who we are and what we stand for.

About Us

About Us

Discover our mission to equip individuals with essential IT skills and industry expertise.

Read More →
UnCodeMy Gallery

UnCodeMy Gallery

Explore highlights from our IT training sessions and success stories.

Read More →
×

Free Resources

Learn, practice and plan your career — bilkul free.

Tutorials

Tutorials

Step-by-step written tutorials to learn any technology at your own pace.

Read More →
Free Counselling

Free Counselling

Book a free video counselling session and pick the right course for you.

Read More →
Online Compiler

Online Compiler

Write, run and test your code online — no setup required.

Read More →
⚡ FREE · NO PYTHON NEEDED

NumPy Shape Checker: Know the Result Shape Before You Run the Code

Enter array shapes to see if they broadcast, multiply with @ or reshape, and why.

  • 📐 Broadcasting, axis by axis
  • ✖️ Matrix multiply rules
  • 🔁 Reshape with -1

How to use the NumPy Array Shape and Broadcasting Checker

  1. 1. Pick the operationBroadcasting (+ - * /), matrix multiply (@) or reshape.
  2. 2. Type the shapesLike (3, 4) or 3,4. Add a third shape for broadcasting if you need it.
  3. 3. CheckSee the result shape, or exactly which axis clashes.

The broadcasting rule

When you add, subtract, multiply or divide arrays of different shapes, NumPy broadcasts them to a common shape without copying data. The rule is short:

  1. Line the shapes up from the right.
  2. A missing dimension on the left counts as 1.
  3. On each axis, the sizes must be equal, or one of them must be 1. A size of 1 is stretched to match.

If any axis breaks rule 3, NumPy raises ValueError: operands could not be broadcast together. This checker shows the comparison axis by axis, so you can see which one fails. Typical fixes are reshape, x[:, None] or np.newaxis to add a size-1 axis where you need it.

Worked example

The sample is the classic case from NumPy's own documentation: shapes (8, 1, 6, 1) and (7, 1, 5) broadcast to (8, 7, 6, 5). Axis by axis from the right: 1 and 5 → 5; 6 and 1 → 6; 1 and 7 → 7; and 8 with a missing axis → 8.

Other things to try:

  • Matrix multiply (3, 4) @ (4, 2) gives (3, 2), because the inner sizes 4 and 4 match. (3, 4) @ (3, 4) fails; the tool suggests using a transpose.
  • Batch matmul: (10, 3, 4) @ (4, 5) gives (10, 3, 5); the batch dimension broadcasts.
  • Reshape (2, 3, 4) to (4, -1) gives (4, 6), because 24 elements ÷ 4 = 6. Reshaping 24 elements to (5, -1) is not possible.

Everything is worked out with the rules above in your browser. No NumPy or Python is loaded.

Frequently asked questions

Why does (3,) + (3, 1) give (3, 3)?

(3,) is treated as (1, 3). With (3, 1), both axes have a 1, so each is stretched to 3, giving (3, 3). This surprises many people.

Is np.dot the same as @?

For 1-D and 2-D arrays, yes. For 3-D and higher, np.dot follows different rules; @ (np.matmul) broadcasts the batch dimensions.

What does -1 mean in reshape?

Work this size out from the total number of elements. Only one dimension can be -1.

Do I have to pay for the numpy array shape and broadcasting checker?

No, it is free. Your first check asks for your name and WhatsApp number one time only. Then the numpy array shape and broadcasting checker and all other Uncodemy tools stay open for you with no form.

More free tools

See all free tools