[Numpy-discussion] svd() and eigh()

Arnar Flatberg arnar.flatberg at gmail.com
Sat Mar 1 12:58:46 EST 2008


On Sat, Mar 1, 2008 at 2:43 PM, devnew at gmail.com <devnew at gmail.com> wrote:
> hi
>  i have a set of images of faces which i make into a 2d array using
>  numpy.ndarray
>  each row represents a face image
>  faces=
>  [[ 173.   87.  ...   88.  165.]
>   [ 158.  103.  ..   73.  143.]
>   [ 180.   87.  ..   55.  143.]
>   [ 155.  117.  ..   93.  155.]]
>
>  from which i can get the mean image =>
>  avgface=average(faces,axis=0)
>  and calculate the adjustedfaces=faces-avgface
>
>  now if i apply svd() i get
>   u, s, vt = linalg.svd(adjustedfaces, 0)
>  # a member posted this
>  facespace=vt.transpose()
>
>  and if i calculate covariance matrix
>  covmat=matrix(adjustedfaces)* matrix(adjustedfaces).transpose()
>  eval,evect=eigh(covmat)
>  evect=sortbyeigenvalue(evect) # sothat largest eval is first
>  facespace=evect* matrix(adjustedfaces)
>
>  what is the difference btw these 2 methods?
See my answer, in your other post

> apparently they yield
>  different values for the facespace.
Not really.

> which should i follow?
The svd is a little less efficient and slightly slower. However it is
clear in implementation and may, in some rare situations, be more
precise.

>  is it possible to calculate eigenvectors using svd()?
Again, see me other response.

>
>  thanks
>  D
>  _______________________________________________
>  Numpy-discussion mailing list
>  Numpy-discussion at scipy.org
>  http://projects.scipy.org/mailman/listinfo/numpy-discussion
>



More information about the NumPy-Discussion mailing list