{"id":20761,"date":"2021-09-22T17:36:35","date_gmt":"2021-09-22T12:06:35","guid":{"rendered":"https:\/\/python-programs.com\/?p=20761"},"modified":"2021-11-22T18:36:13","modified_gmt":"2021-11-22T13:06:13","slug":"python-program-to-sort-the-given-matrix","status":"publish","type":"post","link":"https:\/\/python-programs.com\/python-program-to-sort-the-given-matrix\/","title":{"rendered":"Python Program to Sort the Given Matrix"},"content":{"rendered":"

In the previous article, we have discussed Python Program to Find Unique Elements in a Matrix<\/a><\/p>\n

Given a matrix and the task is to sort 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

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

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

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

Given Matrix :\r\n1 5 3\r\n9 11 2\r\n6 2 3<\/pre>\n

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

The given matrix after sorting: \r\n1 2 2 \r\n3 3 5 \r\n6 9 11<\/pre>\n

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

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

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

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

The given matrix after sorting: \r\n0 1 2 \r\n2 2 3 \r\n4 5 6<\/pre>\n

Program to Sort the Given Matrix in Python<\/h2>\n

Below are the ways to sort the given matrix in python:<\/p>\n