Do these 3 things before closing this tab:
1Fix the driver behind crashes, sound loss and screen glitches2Clear out junk files and repair common Windows errors3Scan for outdated or missing drivers - takes under a minuteUse these 75 NumPy interview questions to practice the skills that matter in data-science work: predicting array shapes, choosing the right indexing behavior, reasoning about broadcasting and axes, and writing concise array operations. Each answer includes a focused example or a practical point to explain aloud. Examples follow the NumPy 2.5 stable documentation.
Array foundations
1. What is a NumPy ndarray?
An ndarray is NumPy’s central N-dimensional array type. Its elements share a data type, and its shape describes how those elements are arranged. For fundamentals, see the NumPy beginner guide.
As an Amazon Associate I earn from qualifying purchases.
2. What does an array’s dimension mean?
The number of axes is its dimension count. A scalar array has zero dimensions, a vector has one, a matrix has two, and a three-dimensional array has three. Check with a.ndim.
3. What is an array’s shape?
shape is a tuple giving the length along each axis. For a = np.array([[1, 2, 3], [4, 5, 6]]), a.shape is (2, 3): two rows and three columns.
#1 Best Overall
4. How do size and shape differ?
a.size is the total number of elements; a.shape gives the per-axis lengths. A shape of (2, 3) has size 6.
5. What does dtype tell you?
dtype specifies how each element is represented, such as an integer or floating-point value. Inspect it with a.dtype. It affects representable values, memory use, and the result of operations.
6. What is itemsize?
a.itemsize reports the number of bytes used by one array element. Total element-buffer storage is generally a.size * a.itemsize, excluding object and other overhead.
Recommended Free Tools
7. How do you create an array from a Python sequence?
Use np.array: a = np.array([[1, 2], [3, 4]]). NumPy infers a suitable dtype unless you provide one with dtype=.
8. When would you use zeros or ones?
Use np.zeros((2, 3)) or np.ones((2, 3)) to create a 2-by-3 array initialized to zero or one. Pass dtype= when the default floating-point dtype is not appropriate.
9. How do arange and linspace differ?
np.arange(0, 10, 2) steps by a specified interval and excludes the stop value. np.linspace(0, 1, 5) returns a specified number of evenly spaced values, including both endpoints by default.
10. How does reshape work?
a.reshape(2, 3) changes the shape without changing the element count: six elements can become shape (2, 3), but not (4, 2). Depending on layout and strides, the result may be a view or a copy.
Quick wins for a faster PC:
Clear out junk files and repair common Windows errorsFree Scan →Scan for outdated or missing drivers - takes under a minuteDriver Scan →Indexing and selection
11. How do you select one element from a 2D array?
Use one index per axis: a[1, 2] selects the element in row 1, column 2, using zero-based indexing.
12. How does slicing work?
a[start:stop:step] selects positions from start up to, but not including, stop. For example, a[1:5:2] selects indices 1 and 3.
13. What do negative indices mean?
Negative indices count backward from the end: a[-1] selects the final element, and a[-2:] selects the final two elements.
14. How do you select a rectangular region of a matrix?
Slice each axis: a[1:3, 0:2] selects rows 1 and 2 and columns 0 and 1. The result has shape (2, 2) when both slices contain two positions.
15. How do you select a whole row or column?
For a 2D array, a[1, :] selects row 1 and a[:, 2] selects column 2. Each selection is one-dimensional unless you preserve a singleton axis with a slice, as in a[1:2, :].
16. How do you select values with a condition?
A Boolean mask selects elements where it is true: a[a > 0] returns the positive values as a one-dimensional result. The mask must be compatible with the indexed dimensions.
17. How do you select specified integer positions?
Integer-array indexing selects the listed positions: a[[0, 2, 2]] selects elements 0, 2, and 2, in that order. Unlike basic slicing, this is advanced indexing and returns a selection rather than a basic slice view.
Rank #2
- Careercup, Easy To Read
- Condition : Good
- Compact for travelling
18. What is the difference between basic and advanced indexing?
Basic indexing uses integers, slices, and combinations of them; slicing can produce a view. Advanced indexing uses integer or Boolean arrays and has different result and memory-sharing behavior. Check whether data is shared when that matters rather than assuming every selection is a copy or view. See NumPy indexing.
19. How can you select several rows or columns?
Use integer arrays for selected positions: a[[0, 2], :] selects rows 0 and 2; a[:, [1, 3]] selects columns 1 and 3. Advanced-indexing selections do not behave like ordinary basic slices.
20. How do you assign values through a selection?
Assign to the indexed target directly: a[a < 0] = 0 replaces negative entries in a. Distinguish this from modifying a separately created selection, whose relationship to the original depends on the indexing mode.
21. What bug can a Boolean mask length mismatch cause?
A mask used on an axis must match that axis’s length. If a has shape (4, 3), a row mask needs four values. A three-value mask cannot select its rows and raises an indexing error.
22. How do you keep a selected row two-dimensional?
Use a slice for the row range: a[1:2, :] has shape (1, n), while a[1, :] has shape (n,). Preserving dimensions can simplify later broadcasting or matrix operations.
Free tools Windows power users keep installed
One-click scans. No signup required.
Views, copies, and memory
23. What is a view?
A view is a distinct array object that refers to the same underlying data as another array. Writing through one can affect the other. Views can avoid copying an array’s data.
24. Does basic slicing create a view?
Basic slicing generally creates a view into the original array. For example, b = a[1:4] can share data with a; verify sharing when it is important instead of assuming it for every operation.
25. Does advanced indexing create a view?
Advanced indexing returns a copy of the selected data, unlike basic slicing’s view behavior. This distinction matters when you mutate a selected result or need to limit extra memory use.
26. How do you make an explicit copy?
Use b = a.copy() when changes to b must not change a. A copy uses additional memory for its data.
27. Why can modifying a slice unexpectedly alter the original?
If the slice is a view, both arrays refer to shared data. For example, b = a[:]; b[0] = 99 can change a[0]. Copy first if the mutation must be isolated.
28. What does array contiguity mean?
Contiguity describes whether elements are laid out in a continuous memory block in a particular order. Check flags such as a.flags.c_contiguous and a.flags.f_contiguous when an interface or algorithm has layout requirements.
29. How do you write mutation-safe code?
Be explicit about ownership: retain a view when shared updates are intended, or copy before editing when the source must remain unchanged. A useful review question is whether the operation returns a view or a copy and what later writes will affect.
Broadcasting and vectorization
30. What is broadcasting?
Broadcasting lets NumPy perform elementwise operations on arrays with compatible shapes without manually repeating data. Compare dimensions from the right: each pair must match or at least one must equal 1. See the broadcasting guide.
The Tool Desk
Outbyte Driver Updater FREEScan for outdated or missing drivers - takes under a minuteDriver Scan →Outbyte PC Repair FREERepair Windows errors before they cause bigger problemsFix Now →31. Does a scalar broadcast across an array?
Yes. For example, a + 3 adds 3 to every element of a. A scalar can participate with arrays of any shape.
Rank #3
32. Can shapes (3, 1) and (1, 4) broadcast together?
Yes. Their aligned dimensions are 3 versus 1 and 1 versus 4, so the result shape is (3, 4).
33. Can shapes (2, 3) and (2,) broadcast together?
No. Aligning from the right compares 3 with 2, and neither is 1. The operation fails with incompatible shapes.
34. How can you add one feature vector to each row?
If X has shape (n, d) and bias has shape (d,), X + bias broadcasts the feature vector across the n rows, producing shape (n, d).
35. What does np.newaxis do?
np.newaxis (also None) inserts a length-one axis. If x has shape (3,), x[:, np.newaxis] has shape (3, 1), which can make the intended broadcast explicit.
36. What does vectorization mean in NumPy?
Vectorization expresses an operation over whole arrays rather than writing a Python loop over individual elements. For example, y = 2 * x + 1 applies the expression elementwise to all entries of x.
37. Are all NumPy operations elementwise?
No. Addition and multiplication with compatible arrays are usually elementwise, while matrix multiplication combines dimensions according to linear-algebra rules. Choose the operator based on the intended mathematics.
38. How do you diagnose a broadcasting error?
Write down both shapes, align them at the right, and inspect every dimension. If a pair neither matches nor includes a 1, the operation cannot broadcast as written; add or reshape an axis only if that matches the intended data relationship.
Windows Errors? Fix Them Before They Spread
Repair common Windows errors and clear accumulated junk for a smoother, more stable PC - no reinstall needed.Free scan · no reinstallCrashes, No Sound, or Screen Glitches?
Random freezes, missing sound and display glitches usually trace back to one bad driver. Find and replace yours safely.Free scan · under a minute39. Does broadcasting physically repeat the smaller array?
Broadcasting generally allows operations to treat singleton dimensions as if repeated; it does not require explicitly constructing repeated copies just to perform the operation. Avoid using a repeat operation unless repeated data itself is needed.
Dtypes and non-finite values
40. How do you choose a dtype?
Choose a dtype that represents the required values and precision while fitting the task’s storage and computation needs. Inspect the inferred dtype or set it explicitly rather than relying on assumptions.
41. How do you convert an array’s dtype?
Use b = a.astype(np.float64) to create an array converted to the requested dtype by default. Casting can lose information when the destination type cannot represent the source values.
42. What happens when you divide integers with /?
True division with / produces a floating-point result rather than truncating to an integer. For example, integer values 3 and 2 produce 1.5.
What’s actually slowing this PC down?
Pick the symptom - the matching free tool is one click away.
43. How do you test for NaN values?
Use np.isnan(a) to get a Boolean array marking NaN entries. NaN does not compare equal to itself, so equality testing is not the right check.
44. How do you check for infinities or any non-finite values?
np.isinf(a) marks positive and negative infinity; np.isfinite(a) marks values that are neither infinite nor NaN. Use np.any on the resulting mask to test whether one is present.
45. What is type promotion?
When operands have different dtypes, NumPy determines a result dtype capable of representing the operation under its promotion rules. Inspect the result’s dtype when precision or integer range matters.
Rank #4
46. How can accidental precision loss happen?
Converting to a narrower or integer dtype can round, truncate, or overflow values that the destination cannot represent. Check the source range and precision requirements before casting, especially for large integers or scientific measurements.
Windows Errors? Fix Them Before They Spread
Repair common Windows errors and clear accumulated junk for a smoother, more stable PC - no reinstall needed.Free scan · no reinstallOutdated Drivers Are Slowing You Down
One free scan finds every outdated or missing driver and matches the right update for your exact hardware.Free scan · exact hardware matchAggregations and axes
47. How do you compute a total, average, minimum, or maximum?
Use methods such as a.sum(), a.mean(), a.min(), and a.max(). With no axis specified, each reduces across the array’s elements.
48. What does axis=0 mean for a 2D sum?
a.sum(axis=0) reduces the rows and returns one total per column. For a shape (2, 3) array, the output shape is (3,).
49. What does axis=1 mean for a 2D sum?
a.sum(axis=1) reduces the columns and returns one total per row. For shape (2, 3), the output shape is (2,). A reliable check is to identify which dimension disappears.
50. How do you retain the reduced axis?
Pass keepdims=True: a.sum(axis=1, keepdims=True) has shape (2, 1) for a 2-by-3 input. Keeping the singleton dimension can help with later broadcasting.
What’s actually slowing this PC down?
Pick the symptom - the matching free tool is one click away.
51. How do you reduce a batch of feature rows?
If data has shape (batch, features), use axis=0 for one aggregate per feature and axis=1 for one aggregate per row. State the shape and meaning of the output when explaining your choice.
52. How do you predict an aggregation’s output shape?
Remove the reduced axes from the shape unless keepdims=True, in which case replace their lengths with 1. For shape (2, 3, 4), reducing over axis=1 yields (2, 4), or (2, 1, 4) with keepdims=True.
53. What is a common axis-confusion bug?
Summing a matrix with the wrong axis gives totals in the wrong direction without necessarily raising an error. For [[1, 2, 3], [4, 5, 6]], axis 0 returns column totals [5, 7, 9]; axis 1 returns row totals [6, 15].
54. How do you aggregate along more than one axis?
Supply a tuple of axes when the operation supports it, such as a.sum(axis=(0, 2)). Predict the result by removing both reduced dimensions, or retaining them as length-one dimensions with keepdims=True.
Free tools Windows power users keep installed
One-click scans. No signup required.
Sorting, uniqueness, and conditions
55. How do sort and argsort differ?
np.sort(a) returns sorted values; np.argsort(a) returns the indices that would order the values. Use the indices when you need to reorder a related array the same way.
56. How do you find unique values?
np.unique(a) returns the distinct values in sorted order. Optional return settings can provide inverse indices or counts when those are needed.
57. How do you count occurrences of each unique value?
Use values, counts = np.unique(a, return_counts=True). The arrays align by position: counts[i] is the count for values[i].
58. What does np.where do?
With a condition and two choices, np.where(condition, x, y) selects from x where the condition is true and from y elsewhere, subject to broadcasting. It is useful for concise elementwise conditional values.
The Tool Desk
Outbyte PC Repair FREEClear out junk files and repair common Windows errorsFree Scan →Outbyte Driver Updater FREEScan for outdated or missing drivers - takes under a minuteDriver Scan →59. How do you constrain values to an interval?
np.clip(a, low, high) limits values below low or above high to those boundaries. It returns the clipped result; assign it back if you need to retain it.
60. How do you select values that meet a condition without an explicit loop?
Use a Boolean mask such as a[a > threshold] to extract matching entries, or np.where(a > threshold, a, 0) to preserve the elementwise layout while replacing other values.
Random generation and reproducibility
61. What is NumPy’s recommended random workflow?
Construct a generator with rng = np.random.default_rng(), then call methods on rng. This gives the code an explicit generator object rather than relying on a shared global random state; see the random sampling documentation.
62. How do you make a random example reproducible?
Supply a seed when constructing the generator, for example rng = np.random.default_rng(42). Re-running the same sequence of generator calls with the same setup makes a useful repeatable example.
63. How do you generate random integers?
Use rng.integers(low, high, size=...). The high bound is excluded by default, so rng.integers(0, 10, size=5) draws five values from 0 through 9.
64. How do you draw random samples from an array?
Use rng.choice(a, size=...) to select values from a. Set replace=False when sampling without replacement, provided the requested sample size is valid for the population.
65. How do you shuffle data?
rng.shuffle(a) shuffles an array in place along its first axis. If the original order must be preserved, shuffle a copy instead.
Linear algebra and practical data tasks
66. How does elementwise multiplication differ from matrix multiplication?
a * b multiplies corresponding elements under broadcasting. a @ b performs matrix multiplication and requires compatible inner dimensions; for shape (m, n) @ (n, p), the result has shape (m, p).
67. What is the difference between dot and matmul?
For two 2D matrices, both commonly perform matrix multiplication. The @ operator is the dedicated matrix-multiplication syntax and follows matmul rules for higher-dimensional stacks; dot has different higher-dimensional behavior. Choose based on the intended dimensions and operation.
68. How do you solve a linear system?
Use np.linalg.solve(A, b) to solve A x = b when the system is suitable for a direct solve. Here A is a square coefficient matrix and b contains the right-hand side values; the output is the solution x.
69. How do you transpose a matrix?
Use a.T for a 2D transpose: shape (m, n) becomes (n, m). For arrays with more axes, be deliberate about axis order rather than assuming a transpose only swaps rows and columns.
70. How do you compute a vector norm?
Use np.linalg.norm(x) for the default vector norm, or pass ord= to select a norm. For matrices and multidimensional arrays, specify axes when you need norms per row, column, or batch.
71. How do you compute pairwise differences between two sets of points?
If X has shape (n, d) and Y has shape (m, d), the expression X[:, None, :] - Y[None, :, :] broadcasts to shape (n, m, d). A norm along the final axis then gives an (n, m) matrix of distances.
72. How can you normalize each row of a matrix?
For a matrix X with shape (n, d), compute row norms with np.linalg.norm(X, axis=1, keepdims=True), then divide X by those norms. Decide how to handle zero-norm rows to avoid division by zero.
73. How would you replace missing numeric values with a column mean?
For NaNs, build a mask with np.isnan(X). Compute column means with an approach that ignores NaNs, such as np.nanmean(X, axis=0), then use broadcasting or np.where to fill missing entries. Check for columns containing only NaNs, since their means are not finite.
74. How would you find rows containing any non-finite values?
Use bad = ~np.isfinite(X).all(axis=1) for a 2D matrix. The result is a Boolean vector of length equal to the row count, true wherever that row contains NaN or infinity.
Do these 3 things before closing this tab:
1Scan for outdated or missing drivers - takes under a minute2Repair Windows errors before they cause bigger problems3Fix the driver behind crashes, sound loss and screen glitches75. How would you explain your approach to a small NumPy data task in an interview?
Start by stating the input shapes and dtypes, then describe the transformation and predict the output shape. Choose indexing, broadcasting, or an aggregation to match the task; mention whether mutation is intended and how you would check edge cases such as empty selections, non-finite values, and incompatible dimensions. NumPy’s quickstart covers the array operations, universal functions, and linear-algebra-style workflows underlying these tasks.
Quick Recap
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.




