All problems
Gram-Schmidt Orthonormalization
Problem
Orthonormalize a list of vectors with the Gram-Schmidt process.
For each vector, subtract its projection onto every previously accepted basis vector, then normalize if the remaining norm exceeds 1e-12. Vectors that reduce to the zero vector are skipped. Return the orthonormal basis as a list of vectors.
Hint
A dependent vector subtracts away completely and should not be appended.
Test cases
case 1
in: [[[1,1],[1,0]]]
expected: [[0.7071067811865475,0.7071067811865475],[0.7071067811865477,-0.7071067811865474]]
case 2
in: [[[1,0],[0,1]]]
expected: [[1,0],[0,1]]
case 3
in: [[[1,1,0],[1,0,1]]]
expected: [[0.7071067811865475,0.7071067811865475,0],[0.40824829046386313,-0.40824829046386296,0.8164965809277261]]
case 4
in: [[[0,0],[1,1]]]
expected: [[0.7071067811865475,0.7071067811865475]]
case 5
in: [[[1,1],[2,2]]]
expected: [[0.7071067811865475,0.7071067811865475]]
Starter codePython
def gram_schmidt(vectors):
# Your code here
pass5 test cases · run your code against them in the editor