iamnotsurewhetherpython-numpycanhelpusdecidewhetheramatrixissingularornot.iamtryingtodecidebasedonthedeterminant, butnumpyisproducingsomevaluesaround1. e-10 andnotsurewhatshouldwechooseforacriticalvalue。
解决方案
usenp.Lina LG.matrix _ rankwithedefaulttolerance.there ' ssomediscussiononthedocstringofthatfunctionwhatisanappproprion
a=NP.random.rand (10,10 ) ) ) ) ) ) ) )。
b=NP.random.rand (10,10 ) ) ) ) ) ) ) )。
b [-1 ]=b [0] b [1] # onerowisalinearcombinationoftwoothers
NP.LinaLG.matrix_rank(a ) )。
10
NP.LinaLG.matrix_rank(b ) )。
9
EFis_invertible(a ) :
. returna.shape [0]==a.shape [1] andnp.Lina LG.matrix _ rank [ a ]==a.shape [0]
.
is_invertible(a ) )。
True
is_invertible(b ) )
假