Machine learning (Part 14)-Matrix multiplication Properties

Coursesteach
7 min readOct 14, 2023

--

Matrix multiplication Properties (Dr Andrew)

Description

Matrix multiplication is really useful since you can pack a lot of computation into just one matrix multiplication operation. But you should be careful of how you use them. In this Tutorial, I want to tell you about a few properties of matrix multiplication.

Sections

Commutative Property

Associative Properties

Identity property

1-Commutative property

When working with just raw numbers or when working with scalars, multiplication is commutative. And what I mean by that is if you take three times five, that is equal to five times three and the ordering of this multiplication doesn’t matter. And this is called the commutative property of multiplication of real numbers. It turns out this property that you can, you know, reverse the order in which you multiply things, this is not true for matrix multiplication.So concretely, if A and B are matrices, then in general, A times B is not equal to B times A. So just be careful of that. It’s not okay to arbitrarily reverse the order in which you are multiplying matrices. So, we say that matrix multiplication is not commutative, it’s a fancy way of saying it. As a concrete example, here are two matrices, matrix 1100 times 0020, and if you multiply these two matrices, you get this result on the right. Now, let’s swap around the order of these two matrices. So, I’m going to take these two matrices and just reverse them. It turns out if you multiply these two matrices, you get the second answer on the right and, you know, real clearly, these two matrices are not equal to each other. So, in fact, in general, if you have a matrix operation like A times B. If A is an m by n matrix and B is an by M matrix, just as an example. Then, it turns out that the matrix A times B right, is going to be an m by m matrix, where as the matrix b x a is going to be an n by n matrix so the dimensions don’t even match, right, so A times B and B times A may not even be the same dimension. In the example on the left, I have all two by two matrices, so the dimensions were the same, but in general reversing the order of the matrices can even change the dimension of the outcome so matrix multiplication is not commutative.

2-Associative Properties

Here’s the next I want to talk about. So, when talking about real numbers, or scalars, let’s see, I have 3 times 5 times 2. I can either multiply 5 times 2 first, and I can compute this as 3 times 10. Or, I can multiply three times five for us and I can compute this as, you know fifteen times two and both of these give you the same answer, right? Each, both of these is equal to thirty so Whether I multiply five times two first or whether I multiply three times five first because well, three times five times two is equal to three times five times two. And this is called the associative property of role number multiplication. It turns out that matrix multiplication is associative. So concretely, let’s say I have a product of three matrices, A times B times C. Then I can compute this either as A times, B times C or I can compute this as A times B, times C and these will actually give me the same answer. I’m not going to prove this, but you can just take my word for it, I guess. So just be clear what I mean by these two cases, let’s look at first one first case. What I mean by that is if you actually want to compute A times B times C, what you can do is you can first compute B times C. So that D equals B time C, then compute A times D. And so this is really computing a times B times C. Or, for this second case, You can compute this as, you can set E equals A times B. Then compute E times C. And this is then the same as a times B times C and it turns out that both of these options will give you, is guaranteed to give you the same answer. And so we say that matrix multiplication does enjoy the associative property. Okay? And don’t worry about the terminology associative and commutative that’s why there’s not really going to use this terminology later in these class, so don’t worry about memorizing those terms.

1-Identity property

Finally, I want to tell you about the identity matrix, which is special matrix. So let’s again make the analogy to what we know of raw numbers, so when dealing with raw numbers or scalar numbers, the number one, is you can think of it as the identity of multiplication, and what I mean by that is for any number Z, the number 1 times z is equal to z times one, and that’s just equal to the number z, right, for any raw number. Z. So 1 is the identity operation and so it satisfies this equation. So it turns out that in the space of matrices as an identity matrix as well. And it’s unusually denoted i, or sometimes we write it as i of n by n we want to make explicit the dimensions. So I subscript n by n is the n by n identity matrix. And so there’s a different identity matrix for each dimension n and are a few examples. Here’s the two by two identity matrix, here’s the three by three identity matrix, here’s the four by four identity matrix. So the identity matrix, has the property that it has ones along the diagonals, right, and so on and is zero everywhere else, and so, by the way the one by one identity matrix is just a number one. This is one by one matrix just and it’s not a very interesting identity matrix and informally when I or others are being sloppy, very often, we will write the identity matrix using fine notation. I draw, you know, let’s go back to it and just write 1111, dot, dot, dot, 1 and then we’ll, maybe, somewhat sloppily write a bunch of zeros there. And these zeros, this big zero, this big zero that’s meant to denote that this matrix is zero everywhere except for the diagonals, so this is just how I might sloppily write this identity matrix She says property that for any matrix A, A times identity i times A A. So that’s a lot like this equation that we have up here. One times z equals z times one, equals z itself so I times A equals A times I equals A. Just make sure we have the dimensions right, so if A is a n by n matrix, then this identity matrix that’s an m by n identity matrix. And if A is m by n then this identity matrix, right, for matrix multiplication make sense that has a m by n matrix because this m has a match up that m And in either case the outcome of this process is you get back to Matrix A, which is m by n.

So whenever we write the identity matrix I, you know, very often the dimension rightwill be implicit from the context. So these two I’s they’ re actually different dimension matrices, one may be N by N, the other is M by M But when we want to make the dimension of the matrix explicit, then sometimes we’ll write to this I subscript N by N, kind of like we have up here. But very often the dimension will be implicit. Finally, just want to point out that earlier I said that A times B is not in general equal to B times A, right? That for most matrices A and B, this is not true. But when B is the identity matrix, this does hold true. That A times the identity matrix does indeed equal to identity times A, it’s just that this is not true for other matrices, B in general. So that’s it for the properties of matrix multiplication. And the special matrices, like the identity matrix I want to tell you about, in the next and final tutorial now linear algebra review. I am going to quickly tell you about a couple of special matrix operations, and after that you know everything you need to know about linear algebra for this course

Please Follow coursesteach with to see latest updates on this story

If you want to learn more about these topics: Python, Machine Learning Data Science, Statistic For Machine learning, Linear Algebra for Machine learning Computer Vision and Research

Then Login and Enroll in Coursesteach to get fantastic content in the data field.

Stay tuned for our upcoming articles because we research end to end , where we will explore specific topics related to Machine Learning in more detail!

Remember, learning is a continuous process. So keep learning and keep creating and Sharing with others!💻✌️

Note:if you are a Machine Learning export and have some good suggestions to improve this blog to share, you write comments and contribute.

if you need more update about Machine Learning and want to contribute then following and enroll in following

👉Course: Machine Learning (ML)

👉📚GitHub Repository

👉 📝Notebook

Do you want to get into data science and AI and need help figuring out how? I can offer you research supervision and long-term career mentoring.
Skype: themushtaq48, email:mushtaqmsit@gmail.com

Contribution: We would love your help in making coursesteach community even better! If you want to contribute in some courses , or if you have any suggestions for improvement in any coursesteach content, feel free to contact and follow.

Together, let’s make this the best AI learning Community! 🚀

👉WhatsApp

👉 Facebook

👉Github

👉LinkedIn

👉Youtube

👉Twitter

References

1- Machine Learning — Andrew

--

--