Python for ML interviews
- Coding
- Asked in most interview loops
- About 1 h 40 min to learn
- 3 vetted resources
What this topic covers
Applied AI coding rounds are almost always in Python, and interviewers notice fluency before they notice correctness: comprehensions instead of index loops, dicts and sets for lookups, deque for queues, and NumPy expressed as whole-array operations rather than nested for-loops. The most common slip is writing a vectorisable computation (pairwise distances, softmax over a batch, a masked mean) as a Python loop. This topic covers the built-in data structures you reach for under pressure, how NumPy arrays, axes and broadcasting actually work, and the vocabulary (shape, axis, dtype, view vs copy) that lets you talk through array code out loud.
Leads to
You’re ready when you can
What interviewers check, from the resources below.
- Explain what axis=0 vs axis=1 means for sum and mean on a 2-D array without running code
- Write a boolean-mask filter and a np.nonzero lookup from memory
- State the two broadcasting compatibility conditions and predict the output shape of (3,2) + (2,)
- Add a new axis with np.newaxis or reshape to turn a 1-D array into a column
- Explain why collections.deque beats a list for a queue and which method pops from the left
- Write a dict-of-lists grouping and a set intersection in one line each
- Use enumerate and zip in a loop instead of range(len(...))
- Describe the difference between a tuple and a list and when a tuple can be a dict key
- State the right-to-left shape comparison rule and apply it to (8,1,6,1) with (7,1,5)
- Implement nearest-centroid lookup for many observations with one broadcasted subtraction and argmin
What to study, in order
Each link opened and checked by hand; the date says when.
Start here
NumPy: the absolute basics for beginners (opens in a new tab)
NumPy documentation · NumPy Developers · 45 min · Free · checked 21 Oct 2026
- Why
- Interviewers judge NumPy fluency by whether you reach for shape, axis and broadcasting instead of a nested loop, and this page is where that vocabulary is defined.
- What to read
- Read “Array fundamentals” through “Broadcasting”, then “More useful array operations”, “Transposing and reshaping a matrix” and “Working with mathematical formulas”.
- What to skip
- “How to save and load NumPy objects”, “Importing and exporting a CSV” and “Plotting arrays with Matplotlib”; they never come up in a coding round.
Free alternative
5. Data Structures (The Python Tutorial) (opens in a new tab)
Python documentation · Python Software Foundation · 35 min · Free · checked 21 Oct 2026
- Why
- Clean use of lists, deques, sets and dicts is the baseline interviewers expect before they even look at your algorithm, and this is the canonical reference for it.
- What to read
- Read 5.1 through 5.6: “More on Lists” (including “Using Lists as Queues” and “List Comprehensions”), “The del statement”, “Tuples and Sequences”, “Sets”, “Dictionaries” and “Looping Techniques”.
- What to skip
- 5.7 “More on Conditions” and 5.8 “Comparing Sequences and Other Types”; skim only if the walrus operator or chained comparisons are new to you.
Go deeper
Broadcasting (opens in a new tab)
NumPy documentation · NumPy Developers · 20 min · Free · checked 21 Oct 2026
- Why
- “Vectorise this loop” is a standard follow-up in ML coding rounds, and broadcasting is the mechanism that makes pairwise distances, outer products and batched normalisation one-liners.
- What to read
- Read “General broadcasting rules” and “Broadcastable arrays”, then work through “A practical example: vector quantization” by hand.
- What to skip
- Nothing; the page is short. Don't memorise the exotic shape examples, memorise the rule.
Companies that test Coding most
Put Python for ML interviews in your plan
Tell us your interview date and hours a day; it lands on the right day, in the right order.