Prepare NumPy interview answers on array shapes, broadcasting, views, copies and numerical checks, with a worked row-normalization example. Start with the question, explain the mechanism, and then state an assumption or tradeoff. The scenarios below are original practice examples, not questions supplied by an employer.
Why use an ndarray instead of a Python list?
An array represents typed numerical data with a shape and supports operations over whole arrays. A list remains useful for heterogeneous objects and flexible general-purpose storage. Explain the workload instead of claiming arrays always win. For a small collection of unrelated objects, converting everything to an array may add complexity. For repeated numerical operations, express the computation in terms of axes and expected output shapes.
How does broadcasting work?
Compare shapes from the trailing dimensions. Compatible dimensions have equal sizes or one of them is one. This allows an operation between different shapes without manually expanding every value. Write the shapes before writing code. Broadcasting compatibility does not mean the calculation expresses the intended business or mathematical operation; a result can be legal and still normalize along the wrong axis.
What is the difference between a view and a copy?
A view shares underlying data, whereas a copy has its own data. Changing shared data can affect another array unexpectedly. When answering, identify the operation and verify its documented behavior rather than assuming all indexing copies or all indexing shares memory. Explain whether the downstream function is allowed to mutate its input. A clear ownership decision can matter more than avoiding one allocation.
What does an axis mean in a reduction?
It identifies the dimension being reduced. For a matrix with observations as rows and features as columns, a reduction over rows differs from a reduction over columns. State the input shape, reduced axis and output shape. Preserve a singleton dimension when that is needed for a later broadcast. Use an asymmetric example so a mistaken axis does not accidentally produce a plausible-looking result.
How do you validate numerical output?
Check shape, dtype, finite values and the assumptions behind division or scaling. Compare small results with hand calculations and use a tolerance appropriate to floating-point arithmetic. Decide what should happen for an all-zero row or missing measurement. Do not let a warning disappear into a large pipeline. Explain how you would distinguish a legitimate extreme value from an invalid input.
Worked example
Original example: a 3-by-2 array stores two measurements for each of three samples. To divide each sample by its own total, compute row totals with a shape of 3-by-1. That shape broadcasts across two columns. A plain length-three total vector cannot broadcast against 3-by-2 in the intended way.
Use rows [2, 6], [1, 3] and [0, 0]. The first two normalized rows should be [0.25, 0.75]. The third needs an explicit zero-total policy: flag it, leave it as zeros or reject it according to the application. The policy is part of the answer, not an implementation afterthought.
Practice plan
Write the shape after each stage of the worked example. Then change the matrix to two samples with three features and explain why an incorrect shape may behave differently. Practice a follow-up about whether the normalization step is allowed to modify the original array.
Use Cluegent during preparation to review your own answer: ask for one incorrect assumption and one follow-up question, then respond again without suggestions. Check current plans before choosing a subscription. Follow the employer's rules during the actual interview.
Sources checked
These official references support the guide. Product details and technical documentation can change; check the linked source for current information.
Where Cluegent helps
Cluegent supports permitted live workflows with transcript context, typed prompts, screenshot-aware answers, resume context, custom response behavior, quick action buttons, and a private desktop overlay. It is most useful when you already understand the subject and need help staying structured under pressure.
Frequently asked questions
Should I memorize broadcasting examples?
Learn the trailing-dimension rule, then work through unfamiliar shapes. Predicting the output is more useful than recalling one expression.
How should I compare floating-point arrays?
Choose an absolute and relative tolerance that fits the calculation and verify shape and missing-value behavior separately.