Gram-Schmidt

According to Wikipedia,

the GramSchmidt process is a method for orthonormalising a set of vectors in an inner product space,

Gram–Schmidt process, Wikipedia

Orthonormalising?

Not only is it “right,” it also makes your life a whole lot easier. If you don’t believe me, just watch the video on Coursera or have a go at it with our best friend, Salman Khan on Khan Academy.

We had to automate the process by writing a Python application. I”m not sure what I like best, learning about it, or coding about it. Me thinks I’ll take the latter.

Here’s a snippet:

def gsBasis(A) :
    B = np.array(A, dtype=np.float_)
    for i in range(B.shape[1]) :
        for j in range(i) :
            B[:, i] = B[:,i] - B[:,i] @ B[:,j] * B[:,j]
        if la.norm(B[:, i]) > verySmallNumber :
            B[:, i] = B[:, i] / la.norm(B[:, i])
        else :
            B[:, i] = np.zeros_like(B[:, i])
    return B

You can view the full code on Github.

Author: Ednalyn C. De Dios

I’ve always been enamored with code and I love data science because of its inherent power to solve real problems. Having grown up in the Philippines, served in the United States Navy, and worked in the nonprofit sector, I am driven to make the world a better place. I have started and participated in numerous campaigns that aim to reduce domestic violence and child abuse in the community.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.