How to decide if a matrix is ​​unique in python-numpy?

I'm not sure if python-numpy can help us decide if the matrix is ​​unique or not. I am trying to solve based on the determinant, but numpy produces some values ​​around 1.e-10 and I'm not sure what we should choose for the critical value.

+7
python numpy
source share
1 answer

Use np.linalg.matrix_rank with a valid default value. There is some discussion on the docstring of this function about what is a suitable clipping for considering a singular value of zero:

 >>> a = np.random.rand(10, 10) >>> b = np.random.rand(10, 10) >>> b[-1] = b[0] + b[1] # one row is a linear combination of two others >>> np.linalg.matrix_rank(a) 10 >>> np.linalg.matrix_rank(b) 9 >>> def is_invertible(a): ... return a.shape[0] == a.shape[1] and np.linalg.matrix_rank(a) == a.shape[0] ... >>> is_invertible(a) True >>> is_invertible(b) False 
+11
source share

All Articles