Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Check if a large matrix is diagonal matrix in python

I have compute a very large matrix M with lots of degenerate eigenvectors(different eigenvectors with same eigenvalues). I use QR decomposition to make sure these eigenvectors are orthonormal, so the Q is the orthonormal eigenvectors of M, and Q^{-1}MQ = D, where D is diagonal matrix. Now I want to check if D is truly diagonal matrix, but when I print D, the matrix is too large to show all of them, so how can I know if it is truly diagonal matrix?

like image 260
JoeJackJessieJames Avatar asked May 10 '17 05:05

JoeJackJessieJames


People also ask

How do you know if a matrix has a diagonal matrix?

Diagonal Matrix A matrix is diagonal if all elements above and below the main diagonal are zero. Any number of the elements on the main diagonal can also be zero. is a diagonal matrix. Diagonal matrices are typically, but not always, square.

How do you check if a matrix is diagonally dominant Python?

Find the sum of all the elements in the row. Subtract the diagonal elements in the row from the sum above to find the sum of the non-diagonal elements in the row. If the diagonal element is less than the sum from Step 2, then the matrix is not a diagonally dominant matrix.

How do you find the diagonal of a Numpy matrix?

Numpy diag() function is used to extract or construct a diagonal 2-d array. It contains two parameters: an input array and k , which decides the diagonal, i.e., k=0 for the main diagonal, k=1 for the above main diagonal, or k=-1 for the below diagonal.


1 Answers

Remove the diagonal and count the non zero elements:

np.count_nonzero(x - np.diag(np.diagonal(x)))
like image 123
donkopotamus Avatar answered Sep 22 '22 12:09

donkopotamus