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.
EasyTechnical
25 practiced
Using pandas, write a Python snippet that computes the rolling 7-day average of column 'value' per user in a DataFrame with columns ['user_id', 'timestamp', 'value']. Show how to: (1) ensure rolling uses a time window (7 days) not a fixed row count, (2) handle missing days per user, and (3) return the result aligned to the original timestamps. Include a brief example DataFrame and the code you would run.
MediumTechnical
20 practiced
Write an async Python function using aiohttp and asyncio that concurrently downloads a list of URLs, limits concurrency to N simultaneous requests using a semaphore, reuses a single ClientSession, handles timeouts and cancellations gracefully, and writes responses to disk. Explain when async I/O is preferable for ML pipelines such as fetching many small files from remote stores.
HardTechnical
18 practiced
List and explain all steps to make a PyTorch training job as reproducible as possible across runs and machines. Include seeding for Python, NumPy, and torch, setting torch.backends.cudnn.deterministic and torch.backends.cudnn.benchmark flags, worker_init_fn for DataLoader, mapping loaded models to device, and remaining sources of nondeterminism. Provide code snippets and discuss performance trade-offs.
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.
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.
Unlock Full Question Bank
Get access to hundreds of Python Programming & ML Libraries interview questions and detailed answers.
Sign in to ContinueJoin thousands of developers preparing for their dream job.