Here, we are first using the numpy.random.randint() function to create an nxn square matrix that contains random integers. The generated integers will be within the range [low, high). And the size argument specifies the size of the matrix. For example, size=(n, n) specifie that the created matrix will have n rows and n columns.
Now, we are using the numpy.triu() function to generate an upper triangular matrix from A. The argument k=0 specifies that the generated matrix U will have all the elements below the principal diagonal zeroed. And the elements across and above the principal diagonal will be copied from A to the created upper triangular matrix.
The output of the mentioned program will be:
A: [[9 1 2] [1 2 3] [9 8 9]] The Upper Triangular Matrix U: [[9 1 2] [0 2 3] [0 0 9]]






0 Comments