Matrices and linear algebra interview questions
15 questions interviewers ask on matrices, from first principles to the follow-ups. The first 3 model answers are free to read; Pro opens the rest.
- Give two ways to read a matrix–vector product.
Row by row, each row dotted with the vector, one output per row; and column by column, a linear combination of the columns with the vector's entries as the amounts. For
[[2, 1], [0, 3], [4, 2]]and(3, −1), both give(5, −3, 10). The column view is what makes "the columns are where the basis vectors land" work. - What is the shape rule for
A @ B?(m, k) @ (k, n) → (m, n): the inner sizes must match and the outer ones remain. A weight vector needs one entry per column, per feature, not per row. - What does a 2 × 2 matrix do to the plane, and how do you read it?
It is a linear transformation: grid lines stay straight, parallel and evenly spaced, and the origin stays put. Its first column is where
e₁lands and its second wheree₂lands, so rotations, stretches, shears and projections can be read straight off the columns. - What does the determinant measure?
- Why is
ABnotBA, and which acts first? - What is
(AB)⁻¹? - How do you tell whether a matrix is close to singular?
- You add a temperature column in Fahrenheit to data that already has Celsius. What happens to linear regression?
- Derive the normal equations.
- Why do libraries not solve linear regression with
inv(X.T @ X)? - What is an eigenvector, and when are a matrix's eigenvectors perpendicular?
- Why is gradient descent slow on unscaled features?
- What is the SVD, and how is it related to the eigendecomposition?
- How does PCA relate to the SVD and the covariance matrix?
- What is the difference between
np.cov(X)andnp.cov(X, rowvar=False, bias=True)?