#66 · Linear Algebra · Easy
⊣ Solve on deep-ml.comCompute the orthogonal projection of a vector onto a line defined by a direction vector. The projection gives the component of the vector that lies along the given direction.
import numpy as np
def orthogonal_projection(v, L):
v = np.array(v, dtype=float)
L = np.array(L, dtype=float)
scalar = np.dot(v, L) / np.dot(L, L)
projection = scalar * L
return projection.tolist()v onto direction L is given by: proj_L(v) = (v . L / L . L) * L.v and L for the numerator.L with itself for the denominator.L to get the projection vector.L and is the closest point on the line to v.