Wrote method to calculate gram matrix