The 60 NumPy questions interviewers actually ask, with direct answers, practice Python snippets, array diagrams, videos, and performance tips.
60 questions with answersKey Takeaways
NumPy is a Python library for fast numerical computing with arrays. Its core object, ndarray, stores homogeneous data in a compact block of memory and supports vectorized operations that run far faster than ordinary Python loops. In interviews, NumPy questions test whether you understand shape, dtype, axes, broadcasting, indexing, slicing, views, copies, and performance. A strong NumPy answer states the input shape, the output shape, and why the operation is vectorized.
Watch: A Practical Introduction to NumPy
Video: A Practical Introduction to NumPy (SciPy, YouTube)
Test yourself and earn a certificate
6 quick questions. Score 70%+ to download your NumPy certificate.
Start here. These are the definitions and first-principle checks that open most rounds.
NumPy is Python's core library for fast numeric arrays and vectorized computation.
It is the base layer for much of the Python data and ML stack.
NumPy changes NumPy decisions by affecting the chosen method, the failure mode, or the validation step. Reliable evidence comes from a metric, test result, query output, log, or review note.
Watch a deeper explanation
Video: A Practical Introduction to NumPy (SciPy, YouTube)
ndarray is NumPy's main array object for storing homogeneous data with a fixed shape.
Homogeneous dtype and shape make fast operations possible.
ndarray changes NumPy decisions by affecting the chosen method, the failure mode, or the validation step. Reliable evidence comes from a metric, test result, query output, log, or review note.
import numpy as np
arr = np.array([1, 2, 3])
print(arr.dtype, arr.shape)Shape is the tuple of dimensions of an array.
A matrix with 3 rows and 4 columns has shape (3, 4).
shape changes NumPy decisions by affecting the chosen method, the failure mode, or the validation step. Reliable evidence comes from a metric, test result, query output, log, or review note.
dtype is the data type of array elements.
Choosing dtype affects memory, precision, and allowed operations.
dtype changes NumPy decisions by affecting the chosen method, the failure mode, or the validation step. Reliable evidence comes from a metric, test result, query output, log, or review note.
| Answer part | What to say | Evidence to mention |
|---|---|---|
| Definition | dtype in one direct sentence. | Official docs or course material |
| Use case | The work where it changes a decision. | Dataset, model, query, dashboard, or pipeline |
| Risk | What breaks when it is misunderstood. | Metric, log, test result, or review note |
Axis is the dimension along which an operation runs.
For a 2D array, axis 0 goes down rows and axis 1 goes across columns.
axis changes NumPy decisions by affecting the chosen method, the failure mode, or the validation step. Reliable evidence comes from a metric, test result, query output, log, or review note.
Watch a deeper explanation
Video: Thinking In Arrays (SciPy, YouTube)
Vectorization applies operations to whole arrays in optimized code instead of Python loops.
This is the main reason NumPy is fast.
vectorization changes NumPy decisions by affecting the chosen method, the failure mode, or the validation step. Reliable evidence comes from a metric, test result, query output, log, or review note.
A ufunc is a universal function that applies elementwise operations to arrays.
Examples include np.add, np.sqrt, np.exp, and np.maximum.
ufunc changes NumPy decisions by affecting the chosen method, the failure mode, or the validation step. Reliable evidence comes from a metric, test result, query output, log, or review note.
Broadcasting lets NumPy apply operations to arrays with compatible shapes without copying data manually.
Compare shapes from the right side to check compatibility.
broadcasting changes NumPy decisions by affecting the chosen method, the failure mode, or the validation step. Reliable evidence comes from a metric, test result, query output, log, or review note.
Key point: the key point is the right-to-left shape rule, not only that broadcasting is fast.
Slicing selects a range of values from an array.
Basic slicing usually returns a view.
slicing changes NumPy decisions by affecting the chosen method, the failure mode, or the validation step. Reliable evidence comes from a metric, test result, query output, log, or review note.
Fancy indexing selects array elements using integer arrays or lists.
It usually returns a copy, not a view.
fancy indexing changes NumPy decisions by affecting the chosen method, the failure mode, or the validation step. Reliable evidence comes from a metric, test result, query output, log, or review note.
Boolean indexing selects elements where a boolean mask is True.
The mask shape must align with the array.
boolean indexing changes NumPy decisions by affecting the chosen method, the failure mode, or the validation step. Reliable evidence comes from a metric, test result, query output, log, or review note.
A view is another way to look at the same underlying data.
Changing a view can change the original array.
view changes NumPy decisions by affecting the chosen method, the failure mode, or the validation step. Reliable evidence comes from a metric, test result, query output, log, or review note.
A copy owns separate data.
Changing a copy does not change the original array.
copy changes NumPy decisions by affecting the chosen method, the failure mode, or the validation step. Reliable evidence comes from a metric, test result, query output, log, or review note.
Watch a deeper explanation
Video: Numerical Computing With NumPy (SciPy, YouTube)
reshape changes array dimensions without changing the data order when possible.
The total number of elements must stay the same.
reshape changes NumPy decisions by affecting the chosen method, the failure mode, or the validation step. Reliable evidence comes from a metric, test result, query output, log, or review note.
concatenate joins arrays along an existing axis.
Shapes must match on all other axes.
concatenate changes NumPy decisions by affecting the chosen method, the failure mode, or the validation step. Reliable evidence comes from a metric, test result, query output, log, or review note.
stack joins arrays along a new axis.
It increases the number of dimensions.
stack changes NumPy decisions by affecting the chosen method, the failure mode, or the validation step. Reliable evidence comes from a metric, test result, query output, log, or review note.
A dot product multiplies corresponding values and sums them.
It is central to linear algebra and neural networks.
dot product changes NumPy decisions by affecting the chosen method, the failure mode, or the validation step. Reliable evidence comes from a metric, test result, query output, log, or review note.
Matrix multiplication combines rows and columns using dot products.
In NumPy, use @ or np.matmul for matrix multiplication.
matrix multiplication changes NumPy decisions by affecting the chosen method, the failure mode, or the validation step. Reliable evidence comes from a metric, test result, query output, log, or review note.
NaN means not a number and commonly represents missing or invalid floating-point values.
Use nan-aware functions such as np.nanmean when needed.
NaN changes NumPy decisions by affecting the chosen method, the failure mode, or the validation step. Reliable evidence comes from a metric, test result, query output, log, or review note.
A random seed makes random number generation repeatable.
Use it for reproducible experiments and tests.
random seed changes NumPy decisions by affecting the chosen method, the failure mode, or the validation step. Reliable evidence comes from a metric, test result, query output, log, or review note.
These questions test whether you can apply the topic to real data, real code, and messy constraints.
Use np.array for data, zeros or ones for initialized arrays, and arange or linspace for numeric ranges.
Choose dtype when memory or precision matters.
creating arrays changes NumPy decisions by affecting the chosen method, the failure mode, or the validation step. Reliable evidence comes from a metric, test result, query output, log, or review note.
a = np.array([1, 2, 3], dtype=np.float32)
b = np.zeros((2, 3))
c = np.linspace(0, 1, 5)Use .shape before doing math or reshaping.
Shape awareness prevents most NumPy mistakes.
checking shape changes NumPy decisions by affecting the chosen method, the failure mode, or the validation step. Reliable evidence comes from a metric, test result, query output, log, or review note.
x = np.ones((4, 3))
print(x.shape) # (4, 3)Key point: The best NumPy answers say the input shape and output shape before the code.
Use reshape when the total element count stays the same.
Use -1 to let NumPy infer one dimension.
reshaping arrays changes NumPy decisions by affecting the chosen method, the failure mode, or the validation step. Reliable evidence comes from a metric, test result, query output, log, or review note.
x = np.arange(12)
print(x.reshape(3, 4))
print(x.reshape(2, -1).shape)Use axis to control which dimension is reduced.
Explain output shape after the reduction.
summing by axis changes NumPy decisions by affecting the chosen method, the failure mode, or the validation step. Reliable evidence comes from a metric, test result, query output, log, or review note.
x = np.array([[1, 2, 3], [4, 5, 6]])
print(x.sum(axis=0)) # column sums
print(x.sum(axis=1)) # row sumsUse scalar broadcasting for simple elementwise math.
NumPy applies the scalar to each element.
broadcasting a scalar changes NumPy decisions by affecting the chosen method, the failure mode, or the validation step. Reliable evidence comes from a metric, test result, query output, log, or review note.
prices = np.array([10, 20, 30])
print(prices * 1.1)Watch a deeper explanation
Video: Introduction to Numerical Computing with NumPy (SciPy, YouTube)
Align shapes from the right and check that dimensions are equal or one of them is 1.
This is a favorite interview topic.
broadcasting arrays changes NumPy decisions by affecting the chosen method, the failure mode, or the validation step. Reliable evidence comes from a metric, test result, query output, log, or review note.
x = np.ones((3, 4))
bias = np.array([1, 2, 3, 4])
print((x + bias).shape) # (3, 4)Create a boolean condition and use it to filter values.
The mask must match the target dimension.
using boolean masks changes NumPy decisions by affecting the chosen method, the failure mode, or the validation step. Reliable evidence comes from a metric, test result, query output, log, or review note.
x = np.array([3, 8, 2, 10])
print(x[x > 5])Pass integer positions to select specific elements or rows.
Remember that fancy indexing returns a copy.
using fancy indexing changes NumPy decisions by affecting the chosen method, the failure mode, or the validation step. Reliable evidence comes from a metric, test result, query output, log, or review note.
x = np.array([10, 20, 30, 40])
print(x[[0, 2, 3]])Use .copy when you need independent data.
This avoids accidental changes through views.
copying arrays changes NumPy decisions by affecting the chosen method, the failure mode, or the validation step. Reliable evidence comes from a metric, test result, query output, log, or review note.
a = np.array([1, 2, 3])
b = a.copy()
b[0] = 99
print(a, b)Remember that basic slices often share data with the original array.
Use np.shares_memory when debugging.
checking view behavior changes NumPy decisions by affecting the chosen method, the failure mode, or the validation step. Reliable evidence comes from a metric, test result, query output, log, or review note.
a = np.array([1, 2, 3, 4])
view = a[1:3]
view[0] = 99
print(a)Use concatenate along an existing axis when shapes match on other axes.
The axis and resulting shape.
concatenating arrays changes NumPy decisions by affecting the chosen method, the failure mode, or the validation step. Reliable evidence comes from a metric, test result, query output, log, or review note.
a = np.ones((2, 3))
b = np.zeros((2, 3))
print(np.concatenate([a, b], axis=0).shape)Use stack when you want to create a new axis.
Stacking increases dimensionality.
stacking arrays changes NumPy decisions by affecting the chosen method, the failure mode, or the validation step. Reliable evidence comes from a metric, test result, query output, log, or review note.
a = np.array([1, 2])
b = np.array([3, 4])
print(np.stack([a, b]).shape)Use @ or np.matmul for matrix multiplication, not *.
* is elementwise multiplication.
matrix multiplication changes NumPy decisions by affecting the chosen method, the failure mode, or the validation step. Reliable evidence comes from a metric, test result, query output, log, or review note.
A = np.array([[1, 2], [3, 4]])
x = np.array([10, 20])
print(A @ x)Use nan-aware functions or masks when arrays contain NaN.
Ordinary mean returns NaN if any value is NaN.
handling NaN values changes NumPy decisions by affecting the chosen method, the failure mode, or the validation step. Reliable evidence comes from a metric, test result, query output, log, or review note.
x = np.array([1.0, np.nan, 3.0])
print(np.nanmean(x))Use NumPy's random generator with a seed for repeatable results.
Prefer default_rng in modern NumPy.
generating random numbers changes NumPy decisions by affecting the chosen method, the failure mode, or the validation step. Reliable evidence comes from a metric, test result, query output, log, or review note.
rng = np.random.default_rng(42)
print(rng.normal(size=3))Subtract mean and divide by standard deviation along the correct axis.
Add a small epsilon or explicit guard if a column has zero variance.
normalizing an array changes NumPy decisions by affecting the chosen method, the failure mode, or the validation step. Reliable evidence comes from a metric, test result, query output, log, or review note.
X = np.array([[1, 2], [3, 4], [5, 6]], dtype=float)
std = X.std(axis=0)
X_scaled = (X - X.mean(axis=0)) / np.where(std == 0, 1, std)
print(X_scaled)Use np.unique with return_counts when you need frequencies.
It is useful for labels and category checks.
finding unique values changes NumPy decisions by affecting the chosen method, the failure mode, or the validation step. Reliable evidence comes from a metric, test result, query output, log, or review note.
labels = np.array(["a", "b", "a"])
values, counts = np.unique(labels, return_counts=True)
print(values, counts)Use sort for values and argsort for indices that would sort values.
argsort is useful for rankings.
sorting arrays changes NumPy decisions by affecting the chosen method, the failure mode, or the validation step. Reliable evidence comes from a metric, test result, query output, log, or review note.
scores = np.array([80, 95, 70])
print(np.argsort(scores)[::-1])Replace Python loops with vectorized operations, ufuncs, broadcasting, and efficient dtypes.
Profile before and after.
speeding up numeric code changes NumPy decisions by affecting the chosen method, the failure mode, or the validation step. Reliable evidence comes from a metric, test result, query output, log, or review note.
NumPy speed path
Use NumPy for numeric arrays and Pandas for labeled table operations.
They work together, but they solve different layers of the problem.
using NumPy with Pandas changes NumPy decisions by affecting the chosen method, the failure mode, or the validation step. Reliable evidence comes from a metric, test result, query output, log, or review note.
Advanced rounds test trade-offs, failure modes, and whether the decision can hold up under production pressure.
Print shapes, align dimensions from the right, and decide whether reshape, expand_dims, or transpose is needed.
Do not guess. Shape debugging is explicit.
shape mismatch error changes NumPy decisions by affecting the chosen method, the failure mode, or the validation step. Reliable evidence comes from a metric, test result, query output, log, or review note.
Shape mismatch debug
Move loop logic into vectorized NumPy operations or ufuncs.
Python loops are often the bottleneck for numeric arrays.
code is slow with loops changes NumPy decisions by affecting the chosen method, the failure mode, or the validation step. Reliable evidence comes from a metric, test result, query output, log, or review note.
Check whether NumPy matched dimensions you did not intend, then reshape explicitly.
Broadcasting can be correct syntactically and wrong logically.
broadcasting gives wrong result changes NumPy decisions by affecting the chosen method, the failure mode, or the validation step. Reliable evidence comes from a metric, test result, query output, log, or review note.
Watch a deeper explanation
Video: Advanced NumPy (SciPy Japan, YouTube)
Explain that slicing returned a view and use copy when independent data is required.
This is a common view-copy interview check.
slice changes original array changes NumPy decisions by affecting the chosen method, the failure mode, or the validation step. Reliable evidence comes from a metric, test result, query output, log, or review note.
Explain that fancy indexing returns a copy, then assign directly with a mask or indices if needed.
View and copy behavior differs by indexing type.
fancy indexing does not change original changes NumPy decisions by affecting the chosen method, the failure mode, or the validation step. Reliable evidence comes from a metric, test result, query output, log, or review note.
Use @ for matrix multiplication and * for elementwise multiplication.
Always check shapes for linear algebra.
matrix multiplication confusion changes NumPy decisions by affecting the chosen method, the failure mode, or the validation step. Reliable evidence comes from a metric, test result, query output, log, or review note.
The input shape and output shape, then choose the axis.
For 2D arrays, axis 0 reduces rows and axis 1 reduces columns.
axis confusion changes NumPy decisions by affecting the chosen method, the failure mode, or the validation step. Reliable evidence comes from a metric, test result, query output, log, or review note.
Use nan-aware functions or filter NaNs before computing summaries.
Do not hide missingness without reporting it.
NaN breaks summary changes NumPy decisions by affecting the chosen method, the failure mode, or the validation step. Reliable evidence comes from a metric, test result, query output, log, or review note.
Inspect dtype and cast when precision or range matters.
Dtype controls memory and numeric behavior.
integer division or dtype issue changes NumPy decisions by affecting the chosen method, the failure mode, or the validation step. Reliable evidence comes from a metric, test result, query output, log, or review note.
Reduce dtype size, avoid unnecessary copies, process in chunks, or use memory mapping.
Memory cost often comes from hidden copies.
large array memory issue changes NumPy decisions by affecting the chosen method, the failure mode, or the validation step. Reliable evidence comes from a metric, test result, query output, log, or review note.
Set and pass a random generator seed.
Reproducibility matters in tests and experiments.
random results not repeatable changes NumPy decisions by affecting the chosen method, the failure mode, or the validation step. Reliable evidence comes from a metric, test result, query output, log, or review note.
Normalize across features or samples based on the model need, then verify output means and variances.
Wrong axis silently changes the meaning.
normalization by wrong axis changes NumPy decisions by affecting the chosen method, the failure mode, or the validation step. Reliable evidence comes from a metric, test result, query output, log, or review note.
Use argsort for simple cases or argpartition for faster top-k on large arrays.
Argpartition is efficient when full sorting is unnecessary.
top-k selection changes NumPy decisions by affecting the chosen method, the failure mode, or the validation step. Reliable evidence comes from a metric, test result, query output, log, or review note.
Use broadcasting to compute pairwise differences without explicit nested loops.
Explain memory cost for very large matrices.
distance matrix task changes NumPy decisions by affecting the chosen method, the failure mode, or the validation step. Reliable evidence comes from a metric, test result, query output, log, or review note.
Use indexing into an identity matrix or create zeros and assign ones by class index.
Check class count and label range.
one-hot encoding changes NumPy decisions by affecting the chosen method, the failure mode, or the validation step. Reliable evidence comes from a metric, test result, query output, log, or review note.
Check matrix shape, rank, conditioning, and whether solve is better than inverse.
Avoid explicit matrix inverse when solving systems.
linear algebra failure changes NumPy decisions by affecting the chosen method, the failure mode, or the validation step. Reliable evidence comes from a metric, test result, query output, log, or review note.
Use NumPy for numeric arrays and Pandas when labels, joins, groups, or missing-data semantics matter.
The right answer is often to use both.
NumPy vs Pandas choice changes NumPy decisions by affecting the chosen method, the failure mode, or the validation step. Reliable evidence comes from a metric, test result, query output, log, or review note.
Validate shapes, dtypes, ranges, NaNs, random seeds, and output invariants.
Array code can fail silently with the wrong shape.
production numeric pipeline changes NumPy decisions by affecting the chosen method, the failure mode, or the validation step. Reliable evidence comes from a metric, test result, query output, log, or review note.
Clarify that NumPy itself is CPU-oriented; GPU array work usually uses libraries such as CuPy, PyTorch, or JAX.
Do not claim NumPy automatically runs on GPU.
GPU expectation changes NumPy decisions by affecting the chosen method, the failure mode, or the validation step. Reliable evidence comes from a metric, test result, query output, log, or review note.
State shape, dtype, axis, memory behavior, and output shape before explaining the operation.
That structure makes array reasoning easy to follow.
senior NumPy answer changes NumPy decisions by affecting the chosen method, the failure mode, or the validation step. Reliable evidence comes from a metric, test result, query output, log, or review note.
NumPy arrays are built for numeric computation. Python lists are general containers. Interviewers often ask this to see whether you understand memory, dtype, and vectorization.
| Area | Python list | NumPy array | Interview takeaway |
|---|---|---|---|
| Data type | Can mix types | Usually one dtype | NumPy gets speed from uniform data |
| Math | Loops or comprehensions | Vectorized operations | NumPy avoids Python-level loops |
| Memory | Object references | Compact typed memory | Arrays are usually more memory efficient |
| Shape | Nested lists can be irregular | Explicit dimensions | Shape drives array operations |
Why NumPy is faster
Vectorized work happens in optimized compiled code.
Scale: Hyring editorial score for interview preparation, not an external benchmark.
Prepare by practicing shapes. Most NumPy interview mistakes come from axis confusion, broadcasting assumptions, or view-copy behavior.
The typical NumPy interview flow
Most rounds reward clear reasoning more than memorized phrasing.
A strong NumPy answer is mostly shape reasoning. The input shape, the axis being reduced or expanded, the output shape, and whether the operation returns a view or copy. Then explain why the vectorized version is faster or safer than a Python loop. That is the difference between knowing syntax and knowing array programming.
If x has shape (100, 20), x.mean(axis=0) returns 20 values and x.mean(axis=1) returns 100 values. Saying this out loud prevents axis confusion. Interviewers often ask follow-ups by changing one dimension to see if you understand the operation or memorized the example.
Broadcasting aligns shapes from the trailing dimensions. Dimensions must match or one of them must be 1. A good answer includes a small example, such as subtracting a feature mean vector of shape (20,) from a data matrix of shape (100, 20).
For reductions, axis tells NumPy which dimension to collapse. That is why a (4, 3) array summed on axis 0 gives 3 values and summed on axis 1 gives 4 values. This wording is easier to remember than row versus column rules alone.
Basic slicing often returns a view, while fancy indexing and boolean indexing return copies. This matters because changing a view can change the original array. Interviewers ask this because silent mutation bugs are common in numeric code and model preprocessing.
NumPy arrays store data in contiguous typed memory when possible. Strides describe how to move through that memory. You do not need to overexplain internals, but mentioning contiguity, copies, and cache-friendly access helps in senior performance questions.
You do not need to memorize every memory-layout detail, but you should know arrays can be row-major or column-major in storage. This matters when reshaping, passing arrays to other libraries, or debugging performance that changes after a transpose.
dtype is not just memory detail. Integer division, overflow, float precision, NaN handling, and casting can change results. For ML or statistics code, say when you would use float64 for precision and when float32 is acceptable for speed or GPU memory.
For simulations and tests, set a random seed or generator so results can be reproduced. Then report the estimate and the number of trials. This turns a Monte Carlo answer into evidence instead of a one-off number that changes every run.
Vectorization is faster because work moves into optimized compiled loops, not because the code has fewer characters. A strong answer still watches memory. Creating a huge intermediate array can be slower or fail, so batching or in-place operations may be the better choice.
reshape, squeeze, expand_dims, ravel, and flatten can change how later code behaves. A useful answer states whether the operation changes data, view status, or only shape metadata. This is especially important before feeding arrays into ML libraries.
For normalization, divide-by-zero and NaN values need handling. For linear algebra, ill-conditioned matrices can make solutions unstable. Mention small safeguards like epsilon, np.where for zero standard deviations, or using solve instead of manually computing an inverse.
For linear systems, np.linalg.solve is usually better than calculating an inverse and multiplying. It is clearer, more stable, and often faster. This is a common interview follow-up because many candidates remember formulas but miss numerical practice.
Pandas, scikit-learn, PyTorch, TensorFlow, and many scientific Python tools use NumPy ideas. how arrays move between tools, when labels or column names are lost, and why checking shape after conversion matters.
When a DataFrame becomes an ndarray, column names and index labels may disappear. Say how you would preserve feature order, target alignment, and train-test separation. This is a common source of silent ML bugs after otherwise correct NumPy code.
Use a tiny input where the expected output can be checked by hand. Then test shape, dtype, edge values, and one failure case. This proves the vectorized code is correct, not just fast.
NumPy is excellent for numeric arrays, but Pandas may be better for labeled tabular cleaning, SciPy for specialized statistics, and PyTorch or TensorFlow for automatic differentiation. The production-ready answer picks the right library instead of forcing every problem into ndarray code.
6 questions, about 4 minutes. Score 70% or higher to earn a shareable certificate.
Hyring's AI Coding Interviewer supports live Python rounds where shape reasoning, vectorization, and clean explanation matter. Use this NumPy bank before data science, ML, or Python screens.
See Hyring AI Coding Interviewer