I am learning SVD by following this MIT course. In this video, the lecturer is finding the SVD for

$$ \begin{pmatrix} 5 & 5 \\ -1 & 7 \end{pmatrix}, $$

which involves finding the eigenvalues for

$$ C^T C = \begin{pmatrix} 26 & 18 \\ 18 & 74 \end{pmatrix}. $$

In the example (at the time in the link above), the lecturer finds eigenvalues

$$\begin{pmatrix}-3/\sqrt{10} \\ 1/\sqrt{10} \end{pmatrix}, \begin{pmatrix} 1/\sqrt{10} \\ 3/\sqrt{10} \end{pmatrix}.$$

But np.linalg.eig produces the opposite vector to the second one:

w, v = np.linalg.eig(C.T*C)
matrix([[-0.9486833 , -0.31622777],
        [ 0.31622777, -0.9486833 ]])



Any scalar multiple of an eigenvector is also an eigenvector. LAPACK (which np.linalg.eig uses under the hood) chooses to return unit-length eigenvectors (good for SVD!), but this still leaves two choices, and there doesn't seem to be a convention for which one to return; it's up to the underlying algorithm (which in turn may depend on the input data).


  • $\begingroup$ thanks for your answer. would you please point out which rule apples for this specific case? $\endgroup$ – Jay Jun 26 '19 at 7:55
  • $\begingroup$ I've had a quick look, but can't see it yet. numpy is calling _umath_linalg.eig ( github.com/numpy/numpy/blob/v1.16.1/numpy/linalg/… ), which seems to in turn use one of the *geev. As the answer in my SO link says, from there you'd need to understand the FORTRAN code underlying that function, and that's deeper than I want to dig for this. $\endgroup$ – Ben Reiniger Jun 26 '19 at 14:18
  • $\begingroup$ thanks for your reply! what does "*geev" mean? $\endgroup$ – Jay Jun 26 '19 at 21:52
  • $\begingroup$ I was trying to reference the different drivers LAPACK uses for solving variants of the eigenproblem; having known about ones named dgeev and zgeev, and having seen somewhere "_geev", I was just trying to indicate the family. As it turns out, there are a lot more: netlib.org/lapack/lug/node32.html#tabdriveseig $\endgroup$ – Ben Reiniger Jun 27 '19 at 0:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.