Python Programing Lab EXERCISE NO : 11(a) EXERCISE - 11(b) EXERCISE - 11(C)

EXERCISE NO : 11(a) 

Description:
A matrix is a two-dimensional data structure. In python, matrix is a nested list. A list is created by placing all the items (elements) inside a square bracket [ ], separated by commas.
Example: A = [[1, 2, 3], [3, 4, 5]]
In the above example A represents a 2 * 3 matrix.
Accessing the elements of a matrix:

Similar to list we can access elements of a matrix by using square brackets [ ] after the variable like a[row-number][col_number].
Example: A = [[1, 2, 3], [3, 4, 5]]


In the above Matrix,
A[0] contains [1, 2, 3]

A[0][0] contains 1

EXERCISE - 11(b) 

Description:



In order to perform addition of two matrices, the two matrices must have same number of rows and same number of columns.

We should use nested for loops to iterate through each row and each column. At each point, We add the corresponding elements in the two matrices and store it in the result.

Example :


Consider, Two 2*2 Matrices, A = [[2, 2], [2, 2]]

B = [[1, 1], [1, 1]]

If we perform Addition, then we will get the resultant matrix: 
[[3, 3], [3, 3]].

EXERCISE - 11(C)


Description:

In order to perform multiplication of two matrices, then the number of columns in first matrix should be equal to the number of rows in second matrix.
When we multiply two matrices by each other, the resulting matrix will have as many columns as the biggest matrix in the equation.
For example, If we are multiplying a 3*3 by a 3*4 matrix, the resulting matrix will be a 3*4.
Example:

Consider two matrices,
A = [[1, 2, 3], [1, 1 ,1]] Which is a 2 * 3 matrix. B = [[1, 1], [2, 1], [3, 1]] Which is a 3 * 2 matrix.

If we perform multiplication of above matrices, then we will get [[14, 6], [6, 3]], Which is a 2*2 matrix.

No comments

JavaFX Scene Builder

  This is an article about the JavaFX Scene Builder. You will get a short introduction about the installation and usage of the software. The...