Multiplying Matrices with Different Dimensions- A Practical Guide
What "Different Dimensions" Actually Means
Matrix multiplication isn't like regular multiplication. You can't just multiply any two matrices together. The dimensions have to line up in a specific way.
The rule: the number of columns in the first matrix must equal the number of rows in the second matrix.
If you have a 2×3 matrix (2 rows, 3 columns) and a 3×4 matrix (3 rows, 4 columns), you can multiply them. The result will be a 2×4 matrix.
But a 2×3 times a 2×4? That doesn't work. No amount of math makes 3 equal 2.
The Multiplication Rule in Plain English
If matrix A is m × n and matrix B is p × q:
- You can multiply A × B only if n = p
- The result matrix will be m × q
Think of it as a compatibility check before you do any actual math. Get this wrong, and your calculator throws an error—or worse, gives you garbage results.
How Matrix Multiplication Actually Works
Forget everything you learned in basic math. Matrix multiplication uses dot products.
For each element in the result, you:
- Take a row from the first matrix
- Take a column from the second matrix
- Multiply corresponding elements
- Add them all up
That's it. Repeat for every element in your result matrix.
A Quick Example
Matrix A (2×2):
[1, 2]
[3, 4]
Matrix B (2×2):
[5, 6]
[7, 8]
Result[0][0] = (1×5) + (2×7) = 5 + 14 = 19
Result[0][1] = (1×6) + (2×8) = 6 + 16 = 22
Result[1][0] = (3×5) + (4×7) = 15 + 28 = 43
Result[1][1] = (3×6) + (4×8) = 18 + 32 = 50
Result matrix:
[19, 22]
[43, 50]
Common Dimension Combinations
| Matrix A | Matrix B | Can Multiply? | Result |
|---|---|---|---|
| 2 × 3 | 3 × 4 | Yes (3 = 3) | 2 × 4 |
| 3 × 2 | 2 × 5 | Yes (2 = 2) | 3 × 5 |
| 4 × 3 | 4 × 2 | No (3 ≠ 4) | — |
| 1 × 4 | 4 × 1 | Yes (4 = 4) | 1 × 1 (scalar) |
| 3 × 3 | 3 × 3 | Yes (3 = 3) | 3 × 3 |
Why A×B ≠ B×A
Matrix multiplication is not commutative. A×B and B×A give different results—or one might not even be possible.
Using the example above:
B×A gives you:
[19, 22]
[43, 50]
Wait—that looks the same. That's a coincidence because of the specific numbers chosen. Try different values and you'll see the difference.
In general:
- A×B and B×A rarely match
- Sometimes only one direction works due to dimension constraints
- When both work, dimensions must match for equality to be possible
When Dimensions Don't Match
If your dimensions don't align, you have three options:
- Transpose one matrix (flip rows and columns)
- Pad with zeros (less common, used in specialized applications)
- Reconsider your approach—you might be solving the wrong problem
Transposing: The Quick Fix
Transposing swaps rows and columns. A 2×3 becomes 3×2.
If you need A×B but A is m×n and B is q×p, check if n=p works. If not, try A×BT or AT×B.
Tools for Matrix Multiplication
You don't have to do this by hand. Here's what works:
| Tool | Best For | Cost |
|---|---|---|
| NumPy (Python) | Large matrices, automation | Free |
| MATLAB | Engineering, academic work | Paid |
| Wolfram Alpha | Quick checks, small matrices | Free tier |
| Graphing calculators | Classroom, exams | Varies |
| Online matrix calculators | One-off calculations | Free |
Getting Started: Step-by-Step
Here's how to multiply two matrices with different dimensions:
- Check dimensions — Write down the dimensions of both matrices
- Verify compatibility — Columns of A must equal rows of B
- Set up the result matrix — It will have rows of A and columns of B
- Calculate each element — Use dot product: row of A × column of B
- Fill in the result — Each sum goes into the corresponding position
Example walkthrough with a 2×3 and a 3×2:
Matrix A (2×3):
[1, 2, 3]
[4, 5, 6]
Matrix B (3×2):
[7, 8]
[9, 10]
[11, 12]
Result will be 2×2.
Result[0][0] = (1×7) + (2×9) + (3×11) = 7 + 18 + 33 = 58
Result[0][1] = (1×8) + (2×10) + (3×12) = 8 + 20 + 36 = 64
Result[1][0] = (4×7) + (5×9) + (6×11) = 28 + 45 + 66 = 139
Result[1][1] = (4×8) + (5×10) + (6×12) = 32 + 50 + 72 = 154
Final result:
[58, 64]
[139, 154]
Where This Actually Matters
Matrix multiplication with different dimensions shows up in:
- Computer graphics — Transforming 3D models requires multiplying 4×4 transformation matrices with 4×1 coordinate vectors
- Neural networks — Each layer multiplies its weights matrix by the input vector
- Data science — Feature matrices multiplied by weight matrices produce predictions
- Physics engines — Coordinate transformations in game development
The dimensions matter because they represent the structure of your data. A 1000×50 matrix might represent 1000 samples with 50 features each. Multiplying by a 50×10 weight matrix gives you 1000 outputs with 10 values each.
The Bottom Line
Matrix multiplication with different dimensions isn't complicated once you understand the compatibility rule. Columns of the first must match rows of the second. The result takes the rows of the first and columns of the second.
Calculate using dot products. Double-check your dimensions before you start. Use a tool for anything larger than 3×3 unless you're practicing the method.
That's it. No more to it.