NumPy shapes: write dimensions before multiplying matrices

← Back to Blog & Articles

Array dimensions specify which operations are defined and what their outputs mean.

Background

Python programs operate on objects through names. These examples refresh practical reasoning about values, state, interfaces, and scientific calculations. Run them in a disposable local environment and inspect the result.

Array dimensions specify which operations are defined and what their outputs mean.

Work through an example

For X with shape (4, 3) and W with shape (3, 2), X @ W has shape (4, 2). The inner dimension three is summed over. Elementwise multiplication is a different operation and should not be substituted without checking its meaning.

Check the reasoning

A calculation that runs can still use the wrong axis. Label rows and columns with their real meaning, such as examples and features, before interpreting the result. Use a small array with distinguishable entries to detect a transposition.

Practice independently

Construct two small arrays with the shapes above. Calculate one output entry by hand, then verify it against matrix multiplication.

Write down your prediction before consulting the result or revisiting the passage. Explain which observation supports your answer and which part depends on an assumption. Revise the explanation if the evidence does not fit. A useful study note records both the conclusion and the steps another learner would need to check it.

Reference

For the language or library contract, consult the NumPy broadcasting documentation.

Continue with the course

Explore the curriculum, preparation, and study format for Python Refresher — Course Articles.


Companion article for Python Refresher — Course Articles. Original commentary and examples © 2026 Choral Software. Source literary works retain their own attribution.

Scroll to Top