[Numpy-discussion] confusion in eigenlib code

gordon nodrogbrown at gmail.com
Tue Apr 1 11:09:13 EDT 2008


hi
i came across some code for eigenface construction from some
images ,using the old Numeric .
http://www.owlnet.rice.edu/~elec301/Projects99/faces/code.html
In the eigenlib.py
http://www.owlnet.rice.edu/~elec301/Projects99/faces/code/eigenlib.py
i  converted the calls to Numeric functions to their numpy equivalents
(to linalg.eigh() and numpy.dot())and ran the code.In this eigenlib.py
i am confused by some parts where they derrive eigenvectors and sort
them

evalues, evectors = LinearAlgebra.eigenvectors(L)
# sort them by eigenvalue and keep the top M_prime
evs = map(None, evalues, evectors)
evs.sort()
evs.reverse()
evs = evs[0:M_prime]

# write those into the directory
v = map(lambda x: x[1], evs)
self.u = []
for k in range(M_prime):
    print(' ' + str(k+1))
    self.u.append(Numeric.matrixmultiply(v[k], self.Phi))
    #self.vector_to_image(self.u[-1], '%s/eig%03d.gif' % (dir, k))

(Here self.Psi is the average face from a collection of face images
and  self.Phi is obtained by substracting Psi from original image
data ...mean centering i guess)

what i can't understand in the above code is that when evs[0:M_prime]
is taken it takes the rows from evectors.Is not the correct way to
take a column of evectors as an eigenvector? If someone can make this
clear please do
thanks
gordon



More information about the NumPy-Discussion mailing list