Data Science, Python, Programming, Science, Education.
corr_mat=np.corrcoef(data, rowvar=False) #calculate the eigenvalues and eigenvectors of the correlation matrix evals, evecs = eigh(corr_mat) #calculate the principal components pc = evecs @ np.diag(np.sqrt(evals)) #rotate the principal components to match the original variables rotated_pc = pc @