I think that is correct... Here is what the final result should look like: http://www.datawrangling.com/media/images/first_16.png If the dimensions for the sample faces don't work out to ( 361 x 361 ) in the end, then you are likely to be missing a transpose somewhere. Also, be aware that the scipy linalg.eig by default returns a vector of eigenvalues and a matrix, but the Matlab eig(), returns 2 matrices ( the eigenvalues are multiplied by an identity matrix to get a diagonal matrix). You can check out the mathesaurus reference sheet for help translating the example into python, but hopefully this will point you in the right direction: see: http://www.mathworks.com/access/helpdesk/help/techdoc/ref/eig.html vs:
help(linalg.eig)
Help on function eig in module scipy.linalg.decomp:
eig(a, b=None, left=False, right=True, overwrite_a=False, overwrite_b=False) Solve ordinary and generalized eigenvalue problem of a square matrix.
Inputs:
a -- An N x N matrix. b -- An N x N matrix [default is identity(N)]. left -- Return left eigenvectors [disabled]. right -- Return right eigenvectors [enabled]. overwrite_a, overwrite_b -- save space by overwriting the a and/or b matrices (both False by default)
Outputs:
w -- eigenvalues [left==right==False]. w,vr -- w and right eigenvectors [left==False,right=True]. w,vl -- w and left eigenvectors [left==True,right==False]. w,vl,vr -- [left==right==True].
Definitions:
a * vr[:,i] = w[i] * b * vr[:,i]
a^H * vl[:,i] = conjugate(w[i]) * b^H * vl[:,i]
where a^H denotes transpose(conjugate(a)).
On Sat, Mar 1, 2008 at 12:41 AM, devnew@gmail.com <devnew@gmail.com> wrote:
matlab example should be easy to translate to scipy/matplotlib using
On Mar 1, 12:57 am, "Peter Skomoroch" wrote: I think the
montage function:
load faces.mat %Form covariance matrix C=cov(faces'); %build eigenvectors and eigenvalues [E,D] = eig(C);
hi Peter, nice code..ran the examples.. however couldn't follow the matlab code since i have no exposure to matlab..was using numpy etc for calcs could you confirm the layout for the face images data? i assumed that the initial face matrix should be faces=a numpy matrix with N rows ie N=numofimages
row1=image1pixels as a sequence row2=image2pixels as a sequence ... rowN=imageNpixels as a sequence
and covariancematrix=faces*faces_transpose
is this the right way? thanks _______________________________________________ Numpy-discussion mailing list Numpy-discussion@scipy.org http://projects.scipy.org/mailman/listinfo/numpy-discussion
-- Peter N. Skomoroch peter.skomoroch@gmail.com http://www.datawrangling.com