On 5 February 2013 05:08, eryksun <eryk...@gmail.com> wrote: > On Mon, Feb 4, 2013 at 7:21 PM, Oscar Benjamin > <oscar.j.benja...@gmail.com> wrote: >> eigenvalues, eigenvectors = np.linalg.eig(C) > > First sort by eigenvalue magnitude: > > >>> idx = np.argsort(eigenvalues)[::-1] > >>> print idx > [ 0 1 2 3 8 10 11 12 14 22 20 21 18 19 23 24 17 16 15 13 9 7 5 6 > 4] > > >>> eigenvalues = eigenvalues[idx] > >>> eigenvectors = eigenvectors[:, idx] > >> # 2D PCA - get the two eigenvectors with the largest eigenvalues >> v1, v2 = eigenvectors[:,:2].T
Thanks. I thought that eig already sorted them. The doc claims says that the values are "not necessarily ordered" but when I run it they are in descending order of absolute value. Also I should have used eigh since the covariance matrix is Hermitian (eigh seems to give the eigenvalues in ascending order). Oscar _______________________________________________ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor