{"id":21451,"date":"2021-09-22T17:39:09","date_gmt":"2021-09-22T12:09:09","guid":{"rendered":"https:\/\/python-programs.com\/?p=21451"},"modified":"2021-11-22T18:35:42","modified_gmt":"2021-11-22T13:05:42","slug":"python-program-to-find-the-row-with-maximum-number-of-1s-in-matrix","status":"publish","type":"post","link":"https:\/\/python-programs.com\/python-program-to-find-the-row-with-maximum-number-of-1s-in-matrix\/","title":{"rendered":"Python Program to Find the Row with Maximum Number of 1s in Matrix"},"content":{"rendered":"

In the previous article, we have discussed Python Program for Markov Matrix<\/a><\/p>\n

Given a matrix with just 0 and 1 elements, the task is to find the row in the matrix with the greatest number of 1s in that row 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 0 0\r\n1 1 1\r\n1 0 1<\/pre>\n

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

The row which is containing maximum number of 1 is : 2<\/pre>\n

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

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

Given Matrix : \r\n1 1 0\r\n0 0 1\r\n0 1 1<\/pre>\n

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

The row which is containing maximum number of 1 is : 3<\/pre>\n

Note: <\/strong>If both the rows are having the same number of 1’s then it prints the last row.<\/p>\n

Program to Find the Row with Maximum Number of 1s in Matrix in Python<\/h2>\n

Below are the ways to find the row in the matrix with the greatest number of 1s in that row in Python:<\/p>\n