I have a for
-loop with generates random Hermitian matrices using a function, diagonalizes it and stores the eigenvalues. However, for some of the instances the diagonalization fails to converge and the code stops.
I want that, if the diagonalization fails, it should skip to the next instance. As a pseudo code:
vals_list = []
for i in range(1000):
M = random_matrix(....) #generates a 2D numpy array
vals,vecs = np.linalg.eigh(M)
vals_list.append(vals)
How to modify this to have skip the instances when the diagonalization does not converge?