NumPy

NumPy Interview Q&A for Data Science

Array computing fundamentals that power most Python-based ML pipelines.

1What is NumPy?easy
Answer: NumPy is a high-performance library for numerical computing with multidimensional arrays.
2What is ndarray?easy
Answer: Core NumPy object representing homogeneous n-dimensional array.
3Why NumPy faster than Python lists?medium
Answer: Contiguous memory layout and vectorized C-level operations reduce Python loop overhead.
4What is broadcasting?medium
Answer: Mechanism allowing arithmetic on arrays of different shapes under compatibility rules.
5What are shape and ndim?easy
Answer: shape gives dimensions tuple; ndim gives number of axes.
6What is slicing in NumPy?easy
Answer: Selecting subarrays using index ranges; often returns a view, not copy.
7View vs copy in NumPy?medium
Answer: View shares memory with original array; copy creates independent data.
8What is vectorization?easy
Answer: Applying operations to whole arrays at once instead of explicit Python loops.
9How to handle missing values with NumPy?medium
Answer: Use np.nan and nan-aware functions like np.nanmean, np.nanstd.
10What is boolean indexing?easy
Answer: Filtering array elements using boolean masks.
11What are axis-based operations?medium
Answer: Aggregations like sum/mean can be done row-wise or column-wise via axis parameter.
12How does matrix multiplication work in NumPy?medium
Answer: Use @ or np.dot/np.matmul depending on array dimensions.
13What are common array creation methods?easy
Answer: np.array, zeros, ones, arange, linspace, random.
14Typical NumPy pitfall in interviews?hard
Answer: Ignoring shape compatibility and unintended broadcasting leading to silent logic bugs.
15One-line NumPy summary for DS interviews?easy
Answer: NumPy is the numerical engine behind fast, vectorized scientific computing in Python.