Check the upper or lower triangular matrix

Is there a way, using numpy or scipy, to check if the matrix is ​​a lower or upper triangular matrix ?. I know how to make a function to verify this; but I would like to know if these modules have their own functions. I am looking in the documentation but haven't found anything.

+5
source share
1 answer

I would do

np.allclose(mat, np.tril(mat)) # check if lower triangular np.allclose(mat, np.triu(mat)) # check if upper triangular np.allclose(mat, np.diag(np.diag(mat))) # check if diagonal 
+8
source

Source: https://habr.com/ru/post/1206812/


All Articles