def pcasvd(data, keepdim=0, demean=True):
 (nobs, nvars) = data.shape
 x = np.array(data)
 if demean:
  m = x.mean(0)
 else:
  m = 0
 x -= m
 (U, s, v) = np.linalg.svd(x.T, full_matrices=1)
 factors = np.dot(U.T, x.T).T
 if keepdim:
  xreduced = (np.dot(factors[:, :keepdim], U[:, :keepdim].T) + m)
 else:
  xreduced = data
  keepdim = nvars
  ('print reassigning keepdim to max', keepdim)
 evals = ((s ** 2) / (x.shape[0] - 1))
 return (xreduced, factors[:, :keepdim], evals[:keepdim], U[:, :keepdim])

def pcasvd ( data , keepdim = 0 , demean = True ) : ( nobs , nvars ) = data . shape x = np . array ( data ) if demean : m = x . mean ( 0 ) else : m = 0 x -= m ( U , s , v ) = np . linalg . svd ( x . T , full_matrices = 1 ) factors = np . dot ( U . T , x . T ) . T if keepdim : xreduced = ( np . dot ( factors [ : , : keepdim ] , U [ : , : keepdim ] . T ) + m ) else : xreduced = data keepdim = nvars ( 'print reassigning keepdim to max' , keepdim ) evals = ( ( s ** 2 ) / ( x . shape [ 0 ] - 1 ) ) return ( xreduced , factors [ : , : keepdim ] , evals [ : keepdim ] , U [ : , : keepdim ] )
principal components with svd parameters data : ndarray .