Join Our 5-Week ML/AI Engineer Interview Bootcamp 🚀 led by ML Tech Leads at FAANGs
Implement change of basis for a vector, which lets you express the same geometric vector using different coordinate systems. You’ll compute the coordinates of a vector in a new basis using a basis matrix.
Implement the function
Rules:
B as a matrix whose columns are the basis vectors.B is invertible.Output:
| Argument | Type |
|---|---|
| B | np.ndarray |
| v | np.ndarray |
| Return Name | Type |
|---|---|
| value | np.ndarray |
Use np.linalg.solve; avoid explicit inverse.
Return NumPy array.
B is (n,n) invertible; v length n.
Treat the columns of B as basis vectors. The new coordinates x satisfy B @ x = v.
Avoid forming B^{-1} explicitly. Use np.linalg.solve(B, v) to compute x more stably.
Convert inputs to NumPy arrays with dtype=float (if not already), solve for x, then return x directly.