def perform_pca ( A ) : # First subtract the mean M = ( A - numpy . mean ( A . T , axis = 1 ) ) . T # Get eigenvectors and values of covariance matrix return numpy . linalg . eig ( numpy . cov ( M ) )
python pca based on covariance matrix
Computes eigenvalues and eigenvectors of covariance matrix of A . The rows of a correspond to observations the columns to variables .
def perform_pca(A):
    """
    Computes eigenvalues and eigenvectors of covariance matrix of A.
    The rows of a correspond to observations, the columns to variables.
    """
    # First subtract the mean
    M = (A-numpy.mean(A.T, axis=1)).T
    # Get eigenvectors and values of covariance matrix
    return numpy.linalg.eig(numpy.cov(M))