NumPy interview questions test whether you think in arrays: shapes, dtypes, broadcasting and vectorized operations instead of Python loops, and whether you know when an operation returns a view that shares memory or an independent copy. PyPI listed NumPy 2.5.5 (November 15, 2026) as current on November 17, 2026. NumPy 2.0, released in 2024, changed behaviour interviewers like to probe: NEP 50 type promotion, a 64-bit default integer on Windows, copy=False raising when a copy is needed, and removed aliases such as np.float_ and np.NaN.
Below are 30 questions by level, five scenarios and how interviews test this. The library built on top of NumPy is covered in pandas interview questions, and language basics in Python interview questions.
NumPy interview questions: fundamentals (1–10)
- Why use NumPy instead of Python lists? Arrays store one fixed type in contiguous memory, so operations run as compiled loops over raw values, with broadcasting and far less memory. A list stores pointers to separate Python objects.
- What attributes describe an array?
shape,ndim,dtype,size,itemsize,nbytesandstrides. - How do you create arrays?
np.array([...]),np.zeros((3, 4)),np.ones,np.full,np.arange(0, 10, 2),np.linspace(0, 1, 5),np.eye(3), andnp.empty, which is uninitialized, not zeros. - What is a dtype? The element type, such as
int64,float32orbool.astypeconverts and returns a copy; mixing types promotes to a common type. - How does basic indexing work?
a[1, 2],a[:, 0](a column),a[::2]and negative indices. Basic slices return views. - What is boolean masking?
a[a > 0]selects matching elements and returns a copy;np.where(cond, x, y)picks element-wise between two arrays. - What is fancy indexing? Indexing with integer arrays,
a[[0, 2, 4]], which always returns a copy, unlike slicing. - reshape, ravel or flatten?
a.reshape(3, -1)infers the-1dimension and returns a view when it can;ravel()returns a flat view when possible;flatten()always copies. - What does axis mean? The dimension an operation runs along. On a 2-D array,
sum(axis=0)collapses rows and gives one value per column;axis=1gives one per row.keepdims=Truekeeps the shape broadcastable. - * versus @ versus np.dot?
*multiplies element-wise;@(np.matmul) is matrix multiplication with batch support;np.dotis a dot product for 1-D arrays and matrix multiplication for 2-D ones.
Intermediate NumPy questions (11–20)
- State the broadcasting rules. Compare shapes from the trailing dimension; two dimensions are compatible if equal or one of them is 1; missing leading dimensions count as 1. So
(3, 1) + (1, 4)gives(3, 4), while(3,) + (4,)fails. - Views versus copies? A view shares memory, so writing to it changes the original. Slices and
reshapeusually return views; masks and fancy indexing return copies. Check withnp.shares_memory(a, b)and call.copy()when you need independence. - Vectorize a ReLU.
np.maximum(x, 0)ornp.where(x > 0, x, 0)replaces a Python loop and runs many times faster on large arrays. - What are ufuncs? Universal functions such as
np.addandnp.expthat work element-wise with broadcasting and supportout=,where=,.reduceand.accumulate(np.add.accumulateis a cumulative sum). - How do you handle NaN?
np.nan == np.nanis False, so test withnp.isnan. Usenp.nanmeanandnp.nansumto skip NaNs. NaN is a float, so integer arrays cannot hold it. - How should you generate random numbers?
rng = np.random.default_rng(42), thenrng.integers,rng.normalorrng.choice. The Generator API is recommended over the legacy global-statenp.random.seedfunctions. - concatenate, stack, vstack or hstack?
np.concatenatejoins along an existing axis;np.stackadds a new axis;vstackandhstackare row and column shortcuts;np.splitreverses them. - How do you find the top k values quickly?
np.argpartition(a, -k)[-k:]finds the k largest in linear time without a full sort; sort just those k if order matters.np.unique(a, return_counts=True)gives frequencies. - What does ddof change in std?
np.stdusesddof=0(population) by default; passddof=1for the sample standard deviation, which pandas uses by default. - C order versus Fortran order? C order is row-major and Fortran order is column-major; strides say how many bytes to step per dimension. Operations along the contiguous axis are faster;
np.ascontiguousarrayfixes a strided input.
Experienced and senior NumPy questions (21–30)
- How do strides make transpose free?
a.Tswaps the strides and returns a view without moving data. For sliding windows,np.lib.stride_tricks.sliding_window_viewis the safe way to build overlapping views. - What is einsum for? Expressing products and reductions by index labels:
np.einsum('ij,jk->ik', A, B)is matrix multiplication, and'bij,bjk->bik'batches it. - Compute pairwise distances without loops.
np.sqrt(((X[:, None, :] - Y[None, :, :]) ** 2).sum(-1))broadcasts to an n by m by d array, which costs memory; the expansion|x|² + |y|² - 2x·ywith one matrix multiply scales better. - What did NEP 50 change in NumPy 2? Type promotion now depends on dtypes, not values, and Python scalars are "weak":
np.float32(3) + 3.0staysfloat32. Some mixed operations now give lower-precision results than in 1.x. - What else did NumPy 2.0 change? The default integer on 64-bit Windows became int64;
np.array(x, copy=False)raises if a copy is needed (usenp.asarray); aliases such asnp.float_,np.NaNandnp.Infwere removed; the maximum number of dimensions rose from 32 to 64. - What happens on integer overflow? Fixed-width integer arrays wrap around silently: an
int8array holding 127 plus 1 becomes -128. Choose a wide enough dtype; Python's own ints never overflow. - How do you compare floats?
np.iscloseandnp.allclosewith explicitrtolandatol, because0.1 + 0.2 == 0.3is False. - Why is np.append in a loop slow? Each call allocates a new array and copies everything, so a loop is quadratic. Preallocate with
np.empty(n), or collect in a list and convert once. - When do you use np.linalg.solve over inv? Always for solving
Ax = b:np.linalg.solve(A, b)is faster and more numerically stable thannp.linalg.inv(A) @ b. Uselstsqfor over-determined systems. - How do you do group-by sums in pure NumPy?
np.bincount(labels, weights=values)for integer labels, ornp.add.at(out, idx, vals), which handles repeated indices correctly whereout[idx] += valsdoes not.
NumPy scenario and troubleshooting questions
Editing a slice changed the original data. Basic slicing returned a view. Call .copy() when you need an independent array, and say so in code review.
operands could not be broadcast together with shapes (100,3) (100,). The trailing dimensions are 3 and 100. Reshape the second operand to a column with v[:, None], shape (100, 1).
Results changed slightly after upgrading to NumPy 2. Likely NEP 50 promotion keeping float32 where 1.x upcast, or code that relied on removed aliases. Run the tests with warnings as errors and set dtypes explicitly.
A distance matrix runs out of memory. The broadcasted intermediate is n by m by d. Process in chunks, use the matrix-multiply expansion, or drop to float32.
A feature-engineering loop over rows takes minutes. Vectorize it with masks, np.where, cumsum or bincount; for labelled group-by logic, move to pandas.
How NumPy interviews test this
| Format | What it usually looks like | How to prepare |
|---|---|---|
| Concept Q&A | Views versus copies, broadcasting, axis, dtypes | Explain each with a shape example |
| Live coding | Vectorize a loop, normalize rows, pairwise distances, top-k, moving average | Write the experienced answers above from memory |
| Data science round | NumPy inside a pandas or ML exercise | Pair with data scientist interview questions |
| ML engineering | Array shapes in model code, memory and performance | See PyTorch interview questions, where tensors follow the same rules |
Where CoPilot Interview fits
CoPilot Interview is an AI interview assistant. Its free AI mock interview builds NumPy and data science questions from your résumé and the job description, reads them aloud and scores each spoken answer out of 10, which is a fast way to find the answers above that you know but cannot yet explain cleanly under pressure. The browser demo has 145 practice questions in 10 tracks, scores typed answers out of 10 and needs no signup. The free plan gives 15 minutes a day of live help in sessions of up to 15 minutes, with AI mock interviews included. Paid plans are Standard at $24.99 a month and Pro at $39.99 a month, in the desktop app for Windows 10/11 and macOS 12 or later.
Use it to practice. Online assessments, proctored tests, take-home tasks with rules and AI-led rounds forbid outside help, so prepare for those instead of bringing a tool. For any live interview, follow your employer's rules.
Disclosure: CoPilot Interview is our product, so weigh what we say about it accordingly.
Frequently asked questions
What are the most common NumPy interview questions?
Arrays versus lists, broadcasting rules, views versus copies, axis, reshape and ravel versus flatten, boolean masking, element-wise versus matrix multiplication, and vectorizing a loop.
What is the latest version of NumPy?
PyPI listed NumPy 2.5.5, released November 15, 2026, when we checked on November 17, 2026.
Does slicing a NumPy array create a copy?
No. Basic slicing returns a view that shares memory with the original; boolean masks and integer-array indexing return copies.
What is broadcasting in NumPy?
The rule that lets arrays of different shapes combine element-wise by stretching dimensions of size 1, compared from the trailing dimension, without copying data.
How do I practice NumPy for interviews?
Rewrite five loops from your own code as vectorized NumPy, predict each result's shape before running it, and check which operations return views.
Practice this interview before the real one
The AI mock interview builds questions from your resume and the job description, reads them aloud and scores each spoken answer out of 10. Included on the free plan.
Start a mock interview