NumPy foundations practice problems

23 problems · 0 solved

NumPy is the base layer for almost all ML code in Python, and the same ideas carry over to PyTorch and JAX. The key skill is thinking in whole arrays instead of loops, using broadcasting and indexing to do in one line what would take many. These problems build that habit with tasks taken from real model code. You will one-hot encode labels with fancy indexing, turn rows of counts into probabilities, pick the log-probability of the correct token at every position, compute all pairwise distances without a loop, rank scores so ties share a place, pad variable-length token lists into a batch with a mask, average only the real tokens in a padded batch, compute a masked logsumexp that never overflows, cut a sequence into overlapping windows, return the top k values per row with stable ties, and apply a stable softmax inside groups of a flat array. Start with the Easy problems on one-hot encoding and pairwise distances. Then do padding, masking and logsumexp, and finish with top k and grouped softmax. Clean vectorised code is what interviewers look for, and it makes your training code faster and easier to debug.

Easy 10

Medium 9

Hard 4

Related topics

All practice problems