[SciPy-User] bug in svd ?

pratik pratik.mallya@gmail....
Sun Sep 25 11:56:48 CDT 2011

Please ignore this mail...the implementation is working correctly, it
was a silly error on my part.

On Sunday 25 September 2011 11:15 AM, pratik wrote:
> Hi Scipy users,
> I was using the scikits.learn package for pca analysis, but couldn't get
> the desired principal components (which were apparant from the structure
> of the data). So i just took the svd of the covariance matrix of the
> input data (after making the mean 0, of course). But on examining the
> singular values, i found that they are *NOT sorted in decreasing order*
> (as they should be; although i can of course sort it myself now, the
> scikits.learn package depends upon this fact) This is also mentioned in
> the code; that the singular values should be sorted:
>     Returns
>     -------
>     u : ndarray
>         Unitary matrix.  The shape of `u` is (`M`, `M`) or (`M`, `K`)
>         depending on value of ``full_matrices``.
>     s : ndarray
>         The singular values, sorted so that ``s[i] >= s[i+1]``.  `s` is
>         a 1-d array of length min(`M`, `N`).
>     v : ndarray
>         Unitary matrix of shape (`N`, `N`) or (`K`, `N`), depending on
>         ``full_matrices``.
> I am attaching the code and the data for you to examine. Just print out
> the values of the s array in ipython to see what i mean...
> Best,

Pratik Mallya

More information about the SciPy-User mailing list