What is an upper triangular matrix?
An upper triangular matrix is a square matrix in which all the elements below the principal diagonal are zeros. For example, the matrix A given below is an nxn square matrix that is upper triangular.
So, if ai,j is the element of the ith row and jth column of the matrix A, then we can say that the matrix A is an upper triangular matrix if the following condition holds true:
For example, the matrix B given below is a 3×3 square matrix that is upper triangular.
How to create an upper triangular matrix using Python NumPy?
We can use the following Python code to create an upper triangular matrix using NumPy.
import numpy n = 3 A = numpy.random.randint(low=1, high=10, size=(n, n)) U = numpy.triu(A, k=0) print("A: \n", A) print("The Upper Triangular Matrix U: \n", U)
…
0 Comments