 Hello and welcome to this video lecture. Today I will be discussing how to use matrices in NumPy libraries. So by the time that we finish this video lecture, you will be able to create and modify matrices using NumPy library in Python. So before we go ahead and watch the contents of this video lecture, I strongly encourage all of you to go through the basics of using NumPy library as it will help you to understand how do we use arrays and matrices in Python using NumPy library. So what exactly is a matrix? A matrix, the plural of a matrix is matrices is a regular arrangement of numbers in rows and column fashion. So if we are taking a set of numbers and arranging them in rows and columns, I will show you in a moment how then we call that arrangement as a matrix. The rows in the matrix run horizontally and the columns run vertically throughout the given matrix. So one dimensional array is a matrix having one row and it may have n number of columns where n is a positive number. Now why are we required to process or use matrices? Usually the information that is stored in an image is stored in the form of matrix. So whenever we want to process an image, we have to process the matrix that is storing the details of the image. When we want to make some manipulation of a shape, we also have to change the coefficients or the numbers that are present in the matrix which represents the shape. Similarly, if you want to do some complex mathematical computation, you will always have to use a matrix. So matrices are used in all these applications that we just saw. We have a lot of applications which require matrix. These are some of the basic ones. So element arrangement in matrix is as given on the slide. If we have a one dimensional matrix, it is represented by one row and n columns here in this matrix, n is equal to 10 where the number of columns are 10. Similarly, if you have a two dimensional array as shown at the right side of the slide, so you have 10 columns here and you have 5 rows which represent the matrix. So usually even when you are coding in Python, you will come across axis where 0 are the rows and 1 is the column. Moving ahead, we shall now see how to create a matrix using NumPy library. The matrix function returns a matrix from an array type object or a string of data. The syntax is the object of NumPy dot matrix and the data is passed as parameter to the matrix. This is an example of creation of a matrix. You call the array function and pass the array and the data that you want to pass that needs to be embedded as a matrix. Here I am passing three sub arrays and the output is a two dimensional matrix having three rows and four columns. The matrix also can be created using a range function and passing the shape or reshaping the matrix as having five rows and 10 columns. When you want the data to be in the range from 1 to 50 and want to reshape the matrix as having five rows and 10 columns, you can use this function and the reshape module to create a matrix as shown in the slide. We shall look at some of the properties of the matrix. Shape returns the number of rows and columns from a matrix. Shape of 0 returns the number of rows whereas shape of 1 returns the number of columns. Here 0 and 1 are called as the axis. Size returns the number of elements from a matrix. N-D-I-M that is dimensions prints the number of dimensions and item size prints the length of one array element in bytes. We shall see examples of all these properties. I have printed a sample matrix called MTX1 having 50 elements. Matrix dot shape will give me the output 5, 10 specifying the number of rows and columns. Shape of 0 that is the rows, number of rows has 5. Shape of 1 is 10 that is the number of columns. Size that is the size of the matrix is 50. The dimension of the matrix is 2 and the item size that is the size of integer is 8 in bytes. So this is the output that we get of the properties of the array. Now let us see some functions which will help us to modify a matrix. Function transpose helps us to transpose the matrix that is the elements in the rows become the elements in the columns and vice versa. Reshape gives a new shape to an array without changing its data. File returns a contiguous arrangement in a flatted array, resize returns a new array with a specified shape, append function appends value to the end of the array and concatenate function it puts contents of two or more arrays in a single array. Let us see the examples of all these functions. We will continue with the same matrix having size 50. When I call this function reshape and arrange it with two rows and 25 columns what it does is it changes the shape of the existing matrix and prints the same elements of the matrix MTX1 having two in two rows and 25 columns. Similarly when I call the ravel function what it does is it takes the elements from the matrix MTX1 and then prints a contiguous array of one dimension having all the elements of the matrix. Moving ahead when I call the transpose function all the elements in the first row will become the elements in the first column and so on. Moving ahead when I call the resize function and resize the same matrix MTX1 into a matrix of size 10 having rows 10 and columns 10 what it does is it prints basically the first 5 rows as the contents of MTX1 and now we want an array of 10 columns and 10 rows. So the remaining 5 rows are again filled with the same values as MTX1. So now you have an array A which has 10 rows and 10 columns which is filled with the same values twice. Now let us look at how concatenate function works. Here I am creating two different arrays array A and array B and then I am calling the concatenate function and I want to concatenate the contents of A and B into C and in the output we can see that the contents of array A which is a one dimensional array and array B have been concatenated. Similarly I want to concatenate and append the contents of this single dimensional array 50, 100, 150 and 200 to the existing array C which is a one dimensional array. So I pass these elements as data to append to the array C and the output is as shown in the slide. So 1 to 20 is the contents of array C and 50 to 200 that is the last 4 elements are the elements that have been appended. Now here we will stop for a moment and I want to know what is the difference between reshape function and resize function. So if you have understood the concept of resize and reshape the difference is reshape functions gives a new shape to an array without changing its data whereas resize function returns a new array with the specified shape. Let us see an example of both of them. Here this array has a one dimensional matrix having elements 1 to 12 and we want to reshape this one dimensional array into an into a matrix of 4 rows and 3 columns. So I simply called reshape function and it gives me a matrix having 4 rows and 3 columns. Whatever array can be reshaped in any shape as long as the elements required for reshaping are equal the elements should be equal. So we know that in the first one dimensional matrix we have 12 elements and the rearrangement of the elements are is also similar in the reshape function. So we will be having equal elements. So it is possible to use reshape whereas in resize we are having a new array that is it reshapes a two dimensional array to different dimensions. So we are resizing this array of 4 elements to an array of having 2 rows and 4 columns. So similarly you can see that 0 1 2 3 come into the first row and it creates a new array having a new row with the same elements. These are the references you may refer to these references for additional information on creation of matrix. Thank you.