Reputation: 253
I'm implementing the inverse power method to find the maximum eigenvalue of a matrix.Given a matrix $A$ ( n by n matrix ) and a vector $x$ a np.array with shape: (len(A),)
: One of the steps of the implementation involves computing this value:
$q = x^TAx$
The thing is, i don't know if i'm implementing this the rigt way:
q = x.transpose() @ A @ x
Is there a better way to compute this?
Upvotes: 0
Views: 519
Reputation: 318
x = x.reshape(-1, 1) # or x = x.reshape(1, -1) if x is a row vector.
A_times_x = np.matmul(A, x)
q = np.matmul(x.T, A)
instead of np.matmul
, you should be able to use np.dot
as well, but the former is more readable in my opinion.
Upvotes: 1