```python
'''
fastPCA python实现
'''
import numpy as np
import heapq
def fastPCA(A, k):
r, c = A.shape
meanVec = np.mat(np.mean(A, axis=0))
Z = (A - np.tile(meanVec, (r, 1)))
covMatT = np.matmul(Z, Z.T)
D, V = np.linalg.eig(covMatT)
# D = np.mat(D)
temp = np.unique(heapq.nlargest(k, D))
indx = np.argwhere(D >= temp[0]).T.flatten()
D = D[indx]
D = np.diag(D)
V = V[:, indx]
V = Z.T * V
for i in range(k):
V[:, i] = V[:, i]/np.linalg.norm(V[:, i])
pcaA = Z * V
return pcaA, V
参考《数字图像处理与机器视觉》的“基于PCA的人脸特征抽取”。