 part of this video lecture and in this video lecture we shall see how to perform operations in matrices using the NumPy library. So by the end of this session you will be able to perform arithmetic operations on matrices and also perform broadcasting during operations on matrices. I strongly recommend that you go through the basics of NumPy library before proceeding on working on matrices in NumPy libraries. So we have seen this earlier that a matrix is an arrangement of elements in a row and column function and the various applications of matrices is used in image processing. These are also used in shape manipulations and complex mathematical computation. Now this is a very basic arrangement of elements in the matrix. At the left side of the slide you see matrix A having one row and ten columns and at the right you see matrix B having five rows and ten columns respectively. These are some of the basic arithmetic operations that we can perform on two matrices. NumPy.add will return element wise addition between two matrices. It performs element wise addition when two matrices are passed to it. Similarly subtract performs element wise subtraction between two matrices. The dot function performs matrix multiplication between two matrices and the divide function performs element wise division between two matrices. Let us see the examples of all these functions. Let us start with the add function. Now I have a single dimensional array reshaped into a two dimensional array having two rows and five columns. So the elements are arranged in the row and column fashion. Similarly I have an array B10 which has been rearranged to take the shape of two columns five rows. So the elements from 11 to 20 are represented here having two rows and five columns. We perform an addition of matrix A10 and B10 and this is the result that we have. So 11 and 1 gives us 12, 12 and 2 gives us 14 and so on. Let us look at the example of how two matrices are subtracted. Again we have the same matrix A10 having elements from 1 to 10 in the shape of a matrix of dimensions 25. Similarly we have a matrix B10 again in the same shape as matrix A10 and we perform the subtract operation here and we are subtracting the elements of matrix A10 from B10. So if you can see 11 minus 1 gives us the value 10, 12 minus 2 gives us 10 and so on. So all the elements are subtracted from the corresponding elements from matrix A10 and are giving us the value 10. Now let us look at how divide operation is operated on two matrices. We have again the same matrix A10 and B10 and then I am dividing the elements of matrix B10 by the elements of matrix A10 which is giving us the values as displayed. So 11 divided by 1 gives us 11, 12 divided by 2 gives us 6, 13 divided by 3 is giving us 4.33 and so on. Moving ahead, let us see how to perform multiplication of two matrices using the dot function. So firstly let us arrange, let us create a 4 cross 4 matrix and which holds the values from 1 to 16. So I have created a matrix which holds the values from 1 to 16 using a range function and it takes the shape of a 4 cross 4 matrix. Similarly I am creating another matrix B10 which holds the values 11 to 26 and takes the similar shape 4 cross 4 as that of A10 and then I perform the multiplication using the dot function passing the two matrices as parameters which gives us the values as result of the dot product. Now let us see what happens if the dimension of the matrices are different. Say for example I am passing two matrices A10 and B10 having rows 2 and columns 5. So what happens if I run this command is the IDE gives me the error that the shapes 2,5 and 2,5 are not aligned. The reason is multiplication operation requires number of rows and the number of columns of the two matrices to be equal. So that is the reason that you need to take care that whenever you are performing the multiplication that the number of columns and the number of rows of the two different matrices should be equal for the dot operation to give you the results as expected. Let us talk about broadcasting. Broadcasting is a mechanism which allows to perform arithmetic operation on arrays of different shapes. The smaller array if there is any is transformed multiple times to perform some operation on the larger array. Under certain conditions the smaller array is expanded or broadcasted in a way that it has the same shape of the larger array. So say for example you have a larger array and a shorter array and you want to perform some arithmetic computation on those two arrays. So the smaller sized array will be reshaped or broadcasted so that the results won't be affected and you will see the resultant matrix having all the elements as expected. Let us see with example. So here we have a one dimensional array A having three elements, one dimensional array B having one element and we are performing the multiplication operation. So as you can see element one is multiplied with two giving us value two. Element two is again multiplied with two giving us value four and element three is multiplied with two here giving us value six. So this array of size one is broadcasted so that it can be multiplied with elements of A. Now let us see another example. Here we have two matrices matrix A of size four comma three but matrix B is one dimensional having size three. So when we are performing addition matrix B will be broadcasted. How the values zero zero zero plus zero one two will give us the values zero one two and similarly the matrix B or the one dimensional matrix B having elements three will be broadcasted in such a way that the operations on the corresponding matrix will give us the results as expected. So ten plus zero gives us ten, ten plus one when broadcasted gives us value eleven, ten plus two gives us the value twelve and so on. So this is how broadcasting works. Now there are also times that broadcasting will not work because the dimensions are not matching. So when the trailing dimensions of the arrays are unequal, when the trailing dimensions of the arrays are unequal the broadcasting fails. So there are times when broadcasting fails we need to take care that the trailing dimensions of the arrays are equal to perform broadcasting. So this is the example of broadcasting. So these are arrays of different shapes and I am performing the multiplications. So this is the array of the, this is the result of the multiplication and corresponding output is the output of the addition of the two matrices A and B. I will stop here for a moment and I want you to tell me what is the output of the code that is on the slide. Now if I run this code you will get an error. The error will tell you that operands could not be broadcast together with these shapes. So there are times that when the shape is different and the trailing dimensions are unequal broadcasting fails and with this arrangement of the shape of the matrix there is a failure even by using broadcast. So I need to change this shape in a way that it will match and this is the way that we can match or we can use broadcasting to perform addition. So here I have changed the shape of array A10 to having 10 rows and one columns and I have changed the shape of array B10 to having one row and 10 columns which gives me this result as the arrangement of the array in the matrix. So these are the references you may refer to the NumPy documentation and a course on NPTEL platform Python for Data Science for further details of NumPy. Thank you.