Loading...
Implement the Gram-Schmidt process to orthonormalize a set of vectors using NumPy.
Given a list of linearly independent vectors, produce an orthonormal basis where:
The Gram-Schmidt process:
This algorithm is fundamental in CV for creating orthonormal bases in feature spaces.
vectors = [[1, 1, 0], [1, 0, 1], [0, 1, 1]]
[[0.7071, 0.7071, 0.0], [0.4082, -0.4082, 0.8165], [-0.5774, 0.5774, 0.5774]]
Step 1: Normalize first vector v1=[1,1,0] ∥v1∥=12+12+02=2 u1=[21,21,0]=[0.7071,0.7071,0]
Step 2: Orthogonalize second vector v2=[1,0,1] Projection: v2⋅u1=1×0.7071+0×0.7071+1×0=0.7071 w2=[1,0,1]−0.7071×[0.7071,0.7071,0]=[0.5,−0.5,1] ∥w2∥=0.25+0.25+1=1.5≈1.2247 u2=[0.4082,−0.4082,0.8165]
Step 3: Orthogonalize third vector similarly...