Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Check Upper or Lower Triangular Matrix

Is there any way, using numpy or scipy, to check if a matrix is a lower or upper triangular matrix?. I know how make a function for check this; but I'd like know if these modules have their own functions themselves. I'm searching in the documentation but I do not have found anything.

like image 968
Juan Avatar asked Nov 13 '14 15:11

Juan


People also ask

How to check if a matrix is in upper triangular form?

Given a square matrix and the task is to check the matrix is in upper triangular form or not. A square matrix is called upper triangular if all the entries below the main diagonal are zero.

What is a lower triangular matrix?

A triangular matrix is a square matrix in which all elements above or below the main diagonal are zero (0). If all the entries above the main diagonal are zero, it is a lower triangular matrix.

Are all upper and lower triangular matrices diagonalizable?

All upper and lower triangular matrices are diagonalizable. Any square matrix can be factored into the product of a lower triangular matrix and an upper triangular matrix. That is, any matrix can be transformed into a multiplication of triangular matrices.

How do you know if a triangular matrix is invertible?

An upper or lower triangular matrix is invertible if all its elements on the main diagonal are nonzero. In such a case, the inverse of an upper (lower) triangular matrix is also an upper (lower) triangular matrix.


1 Answers

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
  • http://docs.scipy.org/doc/numpy/reference/generated/numpy.tril.html
  • http://docs.scipy.org/doc/numpy/reference/generated/numpy.triu.html
  • http://docs.scipy.org/doc/numpy/reference/generated/numpy.allclose.html
  • http://docs.scipy.org/doc/numpy/reference/generated/numpy.diag.html
like image 110
YXD Avatar answered Oct 13 '22 18:10

YXD