for example, when solving a linear system in scipy, if the A matrix is ill conditioned when solving Ax = b, the following warning is raised :
LinAlgWarning: Ill-conditioned matrix (rcond=7.10124e-19): result may not be accurate. U = scipy.linalg.solve(self.K, self.F)
I thought about computing the rcond value from the A matrix but it would be less efficient than letting it be done by scipy and in most cases the A matrix is well conditioned.
I would like to do something like :
U = scipy.linalg.solve(K, F)
if LinalgWarning:
K += np.identity(K.shape[0])
U = scipy.linalg.solve(K, F)
I tried to do this :
try:
U = scipy.linalg.solve(A, b)
except LinAlgWarning:
A += np.identity(A.shape[0])
U = scipy.linalg.solve(A, b)
But it did not worked (the warning still showed and the except statement was not run)