Given a vector expressed in basis B, find its representation in basis C. Compute the transformation matrix from basis B to basis C and apply it.
import numpy as np
def change_of_basis(B: list[list[float]], C: list[list[float]],
v: list[float]) -> list[float]:
B_mat = np.array(B, dtype=float).T # columns are basis vectors
C_mat = np.array(C, dtype=float).T # columns are basis vectors
# Transformation matrix from B to C: C_inv * B
C_inv = np.linalg.inv(C_mat)
T = C_inv @ B_mat
# Transform the vector
v = np.array(v, dtype=float)
result = T @ v
return np.round(result, 4).tolist()v_B in basis B has standard coordinates B_mat * v_B.