{"id":20139,"date":"2021-09-06T13:38:08","date_gmt":"2021-09-06T08:08:08","guid":{"rendered":"https:\/\/python-programs.com\/?p=20139"},"modified":"2021-11-22T18:36:26","modified_gmt":"2021-11-22T13:06:26","slug":"python-program-to-display-an-upper-triangular-matrix","status":"publish","type":"post","link":"https:\/\/python-programs.com\/python-program-to-display-an-upper-triangular-matrix\/","title":{"rendered":"Python Program to Display an Upper Triangular Matrix"},"content":{"rendered":"

In the previous article, we have discussed Python Program to Display a Lower Triangular Matrix<\/a><\/p>\n

Given a matrix and the task is to display an upper triangular matrix of the given matrix in Python.<\/p>\n

What is a matrix:<\/strong><\/p>\n

A matrix is a rectangular sequence of numbers divided into columns and rows. A matrix element or entry is a number that appears in a matrix.<\/p>\n

Example:<\/strong><\/p>\n

\"\"<\/p>\n

Above is the matrix which contains 5 rows and 4 columns and having elements from 1 to 20.<\/p>\n

In this order, the dimensions of a matrix indicate the number of rows and columns.<\/p>\n

Here as there are 5 rows and 4 columns it is called a 5*4 matrix.<\/p>\n

Upper Triangular Matrix:<\/strong><\/p>\n

An upper triangular matrix is a square matrix in which all of the entries below the major diagonal are zero.<\/p>\n

Examples:<\/strong><\/p>\n

Example1:<\/strong><\/p>\n

Input:<\/strong><\/p>\n

Given Matrix :\r\n5 3 2\r\n6 1 5\r\n4 8 2<\/pre>\n

Output:<\/strong><\/p>\n

The Upper Triangular matrix of the given matrix is : \r\n5 3 2 \r\n0 1 5 \r\n0 0 2<\/pre>\n

Example2:<\/strong><\/p>\n

Input:<\/strong><\/p>\n

Given Matrix :\r\n1 2 3\r\n6 5 4\r\n7 8 9<\/pre>\n

Output:<\/strong><\/p>\n

The Upper Triangular matrix of the given matrix is :\r\n1 2 3 \r\n0 5 4 \r\n0 0 9<\/pre>\n

Program to Display an Upper Triangular Matrix in Python<\/h2>\n

Below are the ways to display an upper triangular matrix of the given matrix in Python:<\/p>\n