Implement vectorized NumPy ops and explain broadcasting

Quick Overview

This question evaluates proficiency in vectorized numerical computing with NumPy, understanding of broadcasting semantics, and awareness of numerical stability and algorithmic time/space complexity when manipulating high-dimensional arrays.

Implement vectorized NumPy ops and explain broadcasting

Company: OpenAI

Role: Machine Learning Engineer

Category: Data Manipulation (SQL/Python)

Difficulty: medium

Interview Round: Onsite

Implement vectorized NumPy code for: (a) computing pairwise cosine similarity between two real-valued matrices X (shape n×d) and Y (shape m×d) without explicit Python loops; (b) computing a numerically stable softmax for a 2D array along the last axis; (c) explaining how broadcasting works if X has shape (n, 1, d) and Y has shape (1, m, d). Analyze time and space complexity, and discuss pitfalls such as unintended broadcasting, dtype issues, and memory usage.

Quick Answer: This question evaluates proficiency in vectorized numerical computing with NumPy, understanding of broadcasting semantics, and awareness of numerical stability and algorithmic time/space complexity when manipulating high-dimensional arrays.

|Home/Data Manipulation (SQL/Python)/OpenAI
OpenAI logo
OpenAI
Aug 11, 2025, 12:00 AM
mediumMachine Learning EngineerOnsiteData Manipulation (SQL/Python)
23
0

Implement vectorized NumPy code for: (a) computing pairwise cosine similarity between two real-valued matrices X (shape n×d) and Y (shape m×d) without explicit Python loops; (b) computing a numerically stable softmax for a 2D array along the last axis; (c) explaining how broadcasting works if X has shape (n, 1, d) and Y has shape (1, m, d). Analyze time and space complexity, and discuss pitfalls such as unintended broadcasting, dtype issues, and memory usage.

Loading comments...