Hello everybody, welcome to our lecture, using matrix algebra in Python. In this video, I'm going to show you how to multiply matrices, how to find the determinant of a matrix, and how to perform additional operations with matrices. Let's import this library numpy and random. Now, I want to create a linspace object again. Let's call it L equal np.linspace. In this case our number, negative eight, eight. Now, nine of them so this is my L. Let's look at the L, it has nine elements. Now I want to build a matrix of, I would call it matrix M is equal the object L.reshape. The Reshape method. I need to choose the dimension of this matrix here so that I will not get any error. What do you think the answer should be? I want you to pause the video and then choose the dimension of this matrix M so that when I run it, I should not get any error. Did you get it? Well done if so. This is how I'll do it. I will make sure that the product of these two numbers equal nine. Nine, 3 times 3 is equal nine. This will not give me any error. L the array shape three-by-three, we have it. Let's create another matrix using random number. I'll say n equal np.random. I want to use a random number. randintegers. Then in this case, I'm going to choose integers between, let's negative 8, 8 again. I want the size of my matrix to be equal to a three by three again. Another challenge for you, do you think the n point eight would be part of this matrix n. Pause the video and answer that question. Did you get it? If so, well done. This is how I will address it. The randint method like you range will not include the upper bound unlike linspace. The linspace contain both negative 8 and positive 8. But like I mentioned in the previous video, you will not include, you will not see number eight in the matrix N. No matter how many time you run, negative 8 will be there, but the number positive 8 will not be there. Now let's learn how to multiply these two matrices. If you want to multiply M by N. Let first, let's use Matmul method. You can multiply two matrices using this method. For example, I can say np.matmultiplication, matrix multiplication. Then we want to multiply M and N. That's it. You'll have your multiplication. Another way to multiply two matrix is using the dot method. To multiply M and N using the dot method, you can do the following, so M.dot(N). You'll see these two results are the same, you get exactly the same method. In addition to that, you can also use the @ symbol. This @ symbol also multiply these two matrix so M@N. It should give you exactly the same results. Now, let's consider this matrix A equal np.array, then it will take a list of rows. Let me see. This has to be between the square bracket, we take a list of rows, so let's say here, they're 1, 2, 3, and then here 4, 5, 6. This is a 2 by 3 matrix, two rows, three columns. Let me create another matrix B, that matrix will become also a 2 by 3 matrix. Let me change this entry little bit. This is a matrix B. If you want to look at it, matrix A looks like this. You want to look how matrix B look like, it look like this. Now these two matrices, if I want to multiply A times b, so A times B, the dimension of A is 2 by 3, and B is also 2 by 3. This multiplication is not possible before this inner dimension are not the same. If I tried to multiply like A dot B, I will get an error because of that dimension. This dimension is a problem here. However, if I take the transpose of B, so if I put T here. In fact, let me that in the next line. Instead of doing A dot B, I'll do, A dot B transpose. This will give me a valid numbers matrix. Think about that. The transpose of B become a 3 by 2, instead of 2 by 3. If you transpose, it becomes a 3 by 2. If you want to see what the B transpose look like, let me just do it here, B dot T. This is the transpose, you see is three rows, two columns. Now let's learn how to find the determinant. Over first one, our matrix and so NP dot linalg. You need to use this function here, linalg dot det, determinant. We'll put our matrix M in there. The matrix determinant is zero. Now, we do the same thing with our matrix, say N. With matrix N, let's see if that determinant also equals 0. Now that's different from zero. If the determinant of a matrix equals 0, we call those metrics singular matrix. Why? Because inverse will not exist. This one for matrix N, we can easily find its inverse, but matrix M, if you're trying to find the inverse, we will get an error. Confirming the more operation with these matrixes. One of the operation is inverse. I can find NP. If I want to find the inverse of matrix N, for example, would be np dot linalg, and then det dot det. I want to find the determinant of that. The determinant already solve the inverse inv, so linalg inv. Now I want to find the inverse of the matrix N. You see we have the result for that. But let's see. If you try to find the inverse of the matrix M, we are going to have an error. It's a singular matrix because the determinant here is equals 0. We call this type of matrix, singular matrix. In addition to inverse method, we can also add metrics. Because M and N have the same dimension, you can add them. You can add them, but you cannot multiply them. You can also take the difference. I can do M minus N also. Well you can do N minus M and vice versa. These are some operations with matrices is not all of them. You can also multiply a constant by a matrix, for example, 2 times M will multiply everybody into in M by 2. Thanks everybody else, I'll see you next time we're going to do more operations with matrices.