def prepca(P, frac=<NUM_LIT:0>):
U,s,v = np.linalg.svd(P)<EOL>varEach = s**<NUM_LIT:2>/P.shape[<NUM_LIT:1>]<EOL>totVar = varEach.sum()<EOL>fracVar = varEach/totVar<EOL>ind = slice((fracVar>=frac).sum())<EOL>Trans = U[:,ind].transpose()<EOL>Pcomponents = np.dot(Trans,P)<EOL>return Pcomponents, Trans, fracVar[ind]<EOL>
Compute the principal components of *P*.  *P* is a (*numVars*,
*numObs*) array.  *frac* is the minimum fraction of variance that a
component must contain to be included.

Return value is a tuple of the form (*Pcomponents*, *Trans*,
*fracVar*) where:

  - *Pcomponents* : a (numVars, numObs) array

  - *Trans* : the weights matrix, ie, *Pcomponents* = *Trans* *
     *P*

  - *fracVar* : the fraction of the variance accounted for by each
     component returned

A similar function of the same name was in the Matlab (TM)
R13 Neural Network Toolbox but is not found in later versions;
its successor seems to be called "processpcs".