Juan
Juan

Reputation: 2103

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.

Upvotes: 18

Views: 8318

Answers (1)

YXD
YXD

Reputation: 32511

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

Upvotes: 23

Related Questions