Working on some matrix algebra here. Sometimes I need to invert a matrix that may be singular or ill-conditioned. I understand it is pythonic to simply do this:
try:
i = linalg.inv(x)
except LinAlgErr as err:
#handle it
but am not sure how efficient that is. Wouldn't this be better?
if linalg.cond(x) < 1/sys.float_info.epsilon:
i = linalg.inv(x)
else:
#handle it
Does numpy.linalg simply perform up front the test I proscribed?