{"id":19486,"date":"2021-08-30T16:06:16","date_gmt":"2021-08-30T10:36:16","guid":{"rendered":"https:\/\/python-programs.com\/?p=19486"},"modified":"2021-11-22T18:37:07","modified_gmt":"2021-11-22T13:07:07","slug":"python-program-to-find-the-position-of-an-element-in-a-matrix","status":"publish","type":"post","link":"https:\/\/python-programs.com\/python-program-to-find-the-position-of-an-element-in-a-matrix\/","title":{"rendered":"Python Program to Find the Position of an Element in a Matrix"},"content":{"rendered":"

In the previous article, we have discussed Python Program to Find the Maximum Element in the Matrix<\/a>
\nGiven a matrix and a number(element) the task is to find the position of the given element in the given matrix in Python.<\/p>\n

If the element does not exist in the given matrix then print the given element doesn’t exist in the given matrix.<\/p>\n

If there are multiple answers we print all of them.<\/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\n2\u00a0 \u00a09\u00a0 \u00a01\r\n11 4\u00a0 \u00a05 \r\n9\u00a0 \u00a02\u00a0 \u00a03\r\n1\u00a0 \u00a02\u00a0 \u00a03\r\nGiven Element = 9<\/pre>\n

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

The given element { 9 } is present at row {1} and column {2}\r\nThe given element { 9 } is present at row {3} and column {1}<\/pre>\n

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

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

Given Matrix :\r\n1   2\r\n3   4\r\nGiven Element =5<\/pre>\n

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

The given element doesnot exist in the given matrix.<\/pre>\n

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

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

Given Matrix :\r\n2\u00a0 \u00a05   6\r\n1   2   3\r\nGiven Element = 5<\/pre>\n

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

The given element { 5 } is present at row {1} and column {2}<\/pre>\n

Program to Find the Position of an Element in a Matrix in Python<\/h2>\n

Below are the ways to find the position of the given element in the given matrix in Python.<\/p>\n