Why do you do this by hand? Should be done with Shogun's PCA class