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?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…