We have the solution for a single principle component of PCA: If we extend this to the matrix of optimized components , we find:

Here, is a diagonal matrix of eigenvalues and contains linearly independant eigenvectors for the corresponding eigenvalues in (since it is orthogonal matrix as required by PCA).

Therefore, is diagonalisable (as it meets the conditions thereof) and we can extract the eigenvectors from the eigendecomposition:

Columns of the -matrix are the principle components, and has to be arranged such that the diagonal of is decreasing (eigenvectors corresponding to biggest eigenvalues first), such that

To do this by hand, we must calculate the eigenvalues and eigenvectors by hand first.

With numpy, we may use:

eigenvalues, eigenvectors = np.linalg.eigh(S)

With eigh being a special variant of eig function for symmetrical matrices (as is)