{"id":20133,"date":"2021-09-06T13:37:36","date_gmt":"2021-09-06T08:07:36","guid":{"rendered":"https:\/\/python-programs.com\/?p=20133"},"modified":"2021-11-22T18:36:27","modified_gmt":"2021-11-22T13:06:27","slug":"python-program-to-find-square-of-a-matrix","status":"publish","type":"post","link":"https:\/\/python-programs.com\/python-program-to-find-square-of-a-matrix\/","title":{"rendered":"Python Program to Find Square of a Matrix"},"content":{"rendered":"

In the previous article, we have discussed Python Program to Print Triangular Number series 1 3 6 10 15 …N<\/a><\/p>\n

Given a matrix and the task is to find the square of each element in 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

\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\r\n7  5  8<\/pre>\n

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

The Square of all elements of the given matrix is :\r\n25 9 4 \r\n36 1 25 \r\n16 64 4 \r\n49 25 64<\/pre>\n

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

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

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

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

The Square of all elements of the given matrix is :\r\n1 4 9 \r\n36 25 16 \r\n49 64 0<\/pre>\n

Program to Find Square of a Matrix in Python<\/h2>\n

Below are the ways to find the square of each element in the given matrix in Python:<\/p>\n