def pPca(data, dim):
 num = data.shape[1]
 data = asmatrix(makeCentered(data))
 W = asmatrix(standard_normal((num, dim)))
 W_ = W[:]
 while True:
  E = ((inv((W.T * W)) * W.T) * data.T)
  (W, W_) = (((data.T * E.T) * inv((E * E.T))), W)
  if (abs((W - W_)).max() < 0.001):
   break
 return W.T

def pPca ( data , dim ) : num = data . shape [ 1 ] data = asmatrix ( makeCentered ( data ) ) W = asmatrix ( standard_normal ( ( num , dim ) ) ) W_ = W [ : ] while True : E = ( ( inv ( ( W . T * W ) ) * W . T ) * data . T ) ( W , W_ ) = ( ( ( data . T * E . T ) * inv ( ( E * E . T ) ) ) , W ) if ( abs ( ( W - W_ ) ) . max ( ) < 0.001 ) : break return W . T
return a matrix which contains the first dim dimensions principal components of data .