InterviewStack.io LogoInterviewStack.io

Python Programming & ML Libraries Questions

Python programming language fundamentals (syntax, data structures, control flow, error handling) with practical usage of machine learning libraries such as NumPy, pandas, scikit-learn, TensorFlow, and PyTorch for data manipulation, model development, training, evaluation, and lightweight ML tasks.

MediumTechnical
20 practiced
Describe NumPy broadcasting rules in detail and illustrate with examples aligning arrays of shapes (3,1) and (1,4) to produce (3,4). Explain how broadcasting works with trailing axes, when dimensions must be 1 or equal, and provide tips to avoid accidental creation of huge temporaries that can blow memory. Include guidance on using np.expand_dims and np.broadcast_to to make intent explicit.
EasyTechnical
22 practiced
Explain the Python exception hierarchy and the difference between Exception and BaseException. Describe best practices for catching exceptions in ML pipelines, especially in long-running training loops: how to handle cleanup, logging, and custom exceptions for dataset or training failures. Provide concrete examples of exceptions you would catch and those you would let bubble up.
MediumTechnical
39 practiced
Write a NumPy-based Python function normalize_columns(X, eps=1e-8) that normalizes each column of a 2D array X (shape n x d) to zero mean and unit variance without explicit Python loops. Ensure numerical stability for near-constant columns and discuss how to perform the operation in-place to reduce memory overhead.
HardTechnical
23 practiced
Implement a custom autograd Function in PyTorch in Python that computes a numerically stable softmax cross-entropy in one operation to reduce intermediate memory usage. Provide a class MyXent(torch.autograd.Function) with static forward and backward methods, using the log-sum-exp trick for stability, and describe what tensors must be saved in ctx for the backward pass. Also discuss ignore_index handling and per-sample weighting.
MediumTechnical
19 practiced
Implement a custom PyTorch Dataset class in Python that reads image file paths and labels from a CSV file. The Dataset must implement __len__ and __getitem__, lazily open images, apply torchvision transforms passed in as an argument, and handle corrupted images gracefully by logging and returning a fallback tensor. Provide code and discuss performance considerations when used with DataLoader num_workers > 0.

Unlock Full Question Bank

Get access to hundreds of Python Programming & ML Libraries interview questions and detailed answers.

Sign in to Continue

Join thousands of developers preparing for their dream job.