0

Here's an example of some code I'm using:

import numpy as np
import numpy.linalg as linalg

A = np.random.random((10,10))
eigenValues,eigenVectors = linalg.eig(A)

idx = eigenValues.argsort()   
eigenValues = eigenValues[idx]
eigenVectors = eigenVectors[:,idx]

What I'm trying to do is plot only the five smallest eigenvectors in a set of many more than five eigenvectors, and then plot them. So how could one choose the first five eigenvectors and then plot them in matplotlib?

0

2 Answers 2

1

The following will select the first five eigenvectors (assuming you've already done the sorting as in your example):

eigenVectors[:,:5]

As to how best to plot a ten-dimensional vector, I am not sure.

Sign up to request clarification or add additional context in comments.

Comments

0

For future readers, here's a code sample that does exactly this:

from pylab import *
N = 10
k = 5
L = 1

x = linspace(-L, L, N)
H = random((N,N))
ls, vs = eig(H)

#find and plot k lowest eigenvalues and eigenvectors
min_values_indices = argsort(ls)[0:k]
for i in min_values_indices:
    plot(x, vs[:,i])

show()

btw - I would've changed the subject of this question to something more informative (such as "numpy - find lowest k eigenvalues and eigenvectors")

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.