1 00:00:00,230 --> 00:00:01,364 In this video, I'd like 2 00:00:01,364 --> 00:00:02,699 to start talking about how to 3 00:00:02,699 --> 00:00:05,020 multiply together two matrices. 4 00:00:05,020 --> 00:00:06,618 We'll start with a special case 5 00:00:06,618 --> 00:00:08,347 of that, of matrix vector 6 00:00:08,350 --> 00:00:12,530 multiplication - multiplying a matrix together with a vector. 7 00:00:12,530 --> 00:00:13,975 Let's start with an example. 8 00:00:13,975 --> 00:00:15,722 Here is a matrix, 9 00:00:15,722 --> 00:00:17,283 and here is a vector, and 10 00:00:17,283 --> 00:00:18,351 let's say we want to 11 00:00:18,351 --> 00:00:21,281 multiply together this matrix 12 00:00:21,281 --> 00:00:24,202 with this vector, what's the result? 13 00:00:24,202 --> 00:00:25,209 Let me just work through this 14 00:00:25,210 --> 00:00:27,058 example and then we 15 00:00:27,058 --> 00:00:29,886 can step back and look at just what the steps were. 16 00:00:29,886 --> 00:00:31,104 It turns out the result of 17 00:00:31,104 --> 00:00:32,912 this multiplication process is going 18 00:00:32,912 --> 00:00:34,554 to be, itself, a vector. 19 00:00:34,560 --> 00:00:35,931 And I'm just going work 20 00:00:35,931 --> 00:00:37,108 with this first and later we'll 21 00:00:37,108 --> 00:00:39,650 come back and see just what I did here. 22 00:00:39,652 --> 00:00:41,228 To get the first element of 23 00:00:41,228 --> 00:00:42,445 this vector I am going 24 00:00:42,445 --> 00:00:44,840 to take these two numbers 25 00:00:44,849 --> 00:00:47,682 and multiply them with 26 00:00:47,682 --> 00:00:49,463 the first row of the 27 00:00:49,463 --> 00:00:51,884 matrix and add up the corresponding numbers. 28 00:00:51,884 --> 00:00:54,223 Take one multiplied by 29 00:00:54,223 --> 00:00:57,430 one, and take 30 00:00:57,430 --> 00:00:58,616 three and multiply it by 31 00:00:58,616 --> 00:01:01,557 five, and that's 32 00:01:01,580 --> 00:01:04,542 what, that's one plus fifteen so that gives me sixteen. 33 00:01:04,542 --> 00:01:06,879 I'm going to write sixteen here. 34 00:01:06,880 --> 00:01:09,926 then for the second row, 35 00:01:09,926 --> 00:01:12,555 second element, I am 36 00:01:12,555 --> 00:01:14,022 going to take the second row 37 00:01:14,022 --> 00:01:15,255 and multiply it by this vector, 38 00:01:15,255 --> 00:01:17,762 so I have four 39 00:01:17,800 --> 00:01:20,554 times one, plus zero 40 00:01:20,554 --> 00:01:21,894 times five, which is 41 00:01:21,894 --> 00:01:25,625 equal to four, so you'll have four there. 42 00:01:25,625 --> 00:01:28,168 And finally for the last 43 00:01:28,168 --> 00:01:30,015 one I have two one times 44 00:01:30,015 --> 00:01:31,540 one five, so two 45 00:01:31,540 --> 00:01:33,791 by one, plus one 46 00:01:33,791 --> 00:01:36,361 by 5, which is equal 47 00:01:36,361 --> 00:01:39,422 to a 7, and 48 00:01:39,422 --> 00:01:43,145 so I get a 7 over there. 49 00:01:43,810 --> 00:01:45,464 It turns out that the 50 00:01:45,464 --> 00:01:48,102 results of multiplying that's 51 00:01:48,102 --> 00:01:50,750 a 3x2 matrix by a 52 00:01:51,030 --> 00:01:53,498 2x1 matrix is also 53 00:01:53,498 --> 00:01:55,504 just a two-dimensional vector. 54 00:01:55,504 --> 00:01:57,034 The result of this is 55 00:01:57,040 --> 00:02:01,975 going to be a 3x1 56 00:02:01,980 --> 00:02:03,945 matrix, so that's why 57 00:02:03,960 --> 00:02:05,737 three by one 3x1 58 00:02:05,750 --> 00:02:07,534 matrix, in other words 59 00:02:07,550 --> 00:02:13,141 a 3x1 matrix is just a three dimensional vector. 60 00:02:13,170 --> 00:02:14,359 So I realize that I 61 00:02:14,359 --> 00:02:16,072 did that pretty quickly, and you're 62 00:02:16,072 --> 00:02:17,078 probably not sure that you can 63 00:02:17,078 --> 00:02:18,530 repeat this process yourself, but 64 00:02:18,530 --> 00:02:20,196 let's look in more detail 65 00:02:20,196 --> 00:02:22,019 at what just happened and what 66 00:02:22,020 --> 00:02:26,618 this process of multiplying a matrix by a vector looks like. 67 00:02:26,618 --> 00:02:28,478 Here's the details of how to 68 00:02:28,478 --> 00:02:30,532 multiply a matrix by a vector. 69 00:02:30,540 --> 00:02:32,014 Let's say I have a matrix A 70 00:02:32,014 --> 00:02:33,355 and want to multiply it by 71 00:02:33,355 --> 00:02:35,637 a vector x. The 72 00:02:35,637 --> 00:02:37,220 result is going to be some 73 00:02:37,220 --> 00:02:39,569 vector y. So the 74 00:02:39,569 --> 00:02:41,334 matrix A is a m 75 00:02:41,334 --> 00:02:43,388 by n dimensional matrix, so 76 00:02:43,388 --> 00:02:45,062 m rows and n columns and 77 00:02:45,062 --> 00:02:46,570 we are going to multiply that by a 78 00:02:46,570 --> 00:02:49,651 n by 1 matrix, in other words an n dimensional vector. 79 00:02:49,651 --> 00:02:51,203 It turns out this 80 00:02:51,203 --> 00:02:54,694 "n" here has to match this "n" here. 81 00:02:54,694 --> 00:02:55,933 In other words, the number of 82 00:02:55,933 --> 00:02:58,560 columns in this matrix, so 83 00:02:58,580 --> 00:03:01,821 it's the number of n columns. 84 00:03:01,821 --> 00:03:03,457 The number of columns here has 85 00:03:03,457 --> 00:03:06,442 to match the number of rows here. 86 00:03:06,442 --> 00:03:09,274 It has to match the dimension of this vector. 87 00:03:09,280 --> 00:03:10,645 And the result of this product 88 00:03:10,645 --> 00:03:15,681 is going to be an n-dimensional 89 00:03:15,761 --> 00:03:19,858 vector y. Rows here. 90 00:03:19,858 --> 00:03:23,009 "M" is going 91 00:03:23,010 --> 00:03:24,972 to be equal to the number 92 00:03:24,972 --> 00:03:28,237 of rows in this matrix "A". 93 00:03:28,250 --> 00:03:31,082 So how do you actually compute this vector "Y"? 94 00:03:31,082 --> 00:03:32,110 Well it turns out to compute 95 00:03:32,110 --> 00:03:34,280 this vector "Y", the process 96 00:03:34,280 --> 00:03:36,860 is to get "Y""I", multiply "A's" 97 00:03:37,200 --> 00:03:38,799 "I'th" row with the 98 00:03:38,799 --> 00:03:40,218 elements of the vector "X" 99 00:03:40,218 --> 00:03:41,623 and add them up. 100 00:03:41,625 --> 00:03:42,464 So here's what I mean. 101 00:03:42,470 --> 00:03:45,035 In order to get the 102 00:03:45,060 --> 00:03:47,847 first element of "Y", 103 00:03:47,847 --> 00:03:49,980 that first number--whatever that turns 104 00:03:49,980 --> 00:03:51,424 out to be--we're gonna take 105 00:03:51,424 --> 00:03:53,012 the first row of the 106 00:03:53,020 --> 00:03:55,486 matrix "A" and multiply 107 00:03:55,486 --> 00:03:57,680 them one at a time 108 00:03:57,680 --> 00:03:59,842 with the elements of this vector "X". 109 00:03:59,842 --> 00:04:01,755 So I take this first number 110 00:04:01,760 --> 00:04:03,912 multiply it by this first number. 111 00:04:03,912 --> 00:04:07,331 Then take the second number multiply it by this second number. 112 00:04:07,331 --> 00:04:09,264 Take this third number whatever 113 00:04:09,264 --> 00:04:10,603 that is, multiply it the third number 114 00:04:10,603 --> 00:04:12,871 and so on until you get to the end. 115 00:04:13,320 --> 00:04:14,578 And I'm gonna add up the 116 00:04:14,578 --> 00:04:16,289 results of these products and the 117 00:04:16,300 --> 00:04:19,918 result of paying that out is going to give us this first element of "Y". 118 00:04:19,922 --> 00:04:21,690 Then when we want to get 119 00:04:21,690 --> 00:04:25,334 the second element of "Y", let's say this element. 120 00:04:25,340 --> 00:04:26,735 The way we do that is we 121 00:04:26,735 --> 00:04:28,688 take the second row of 122 00:04:28,688 --> 00:04:30,078 A and we repeat the whole thing. 123 00:04:30,078 --> 00:04:31,265 So we take the second row 124 00:04:31,265 --> 00:04:32,994 of A, and multiply it 125 00:04:32,994 --> 00:04:34,407 elements-wise, so the elements 126 00:04:34,407 --> 00:04:35,814 of X and add 127 00:04:35,830 --> 00:04:37,460 up the results of the products 128 00:04:37,460 --> 00:04:38,402 and that would give me the 129 00:04:38,402 --> 00:04:40,107 second element of Y. And 130 00:04:40,107 --> 00:04:41,598 you keep going to get and we 131 00:04:41,600 --> 00:04:42,839 going to take the third row 132 00:04:42,850 --> 00:04:44,720 of A, multiply element Ys 133 00:04:44,720 --> 00:04:47,558 with the vector x, 134 00:04:47,560 --> 00:04:48,682 sum up the results and then 135 00:04:48,682 --> 00:04:50,246 I get the third element and so 136 00:04:50,260 --> 00:04:51,600 on, until I get down 137 00:04:51,600 --> 00:04:55,139 to the last row like so, okay? 138 00:04:55,676 --> 00:04:57,930 So that's the procedure. 139 00:04:58,340 --> 00:05:00,685 Let's do one more example. 140 00:05:00,685 --> 00:05:05,240 Here's the example: So let's look at the dimensions. 141 00:05:05,240 --> 00:05:08,428 Here, this is a three 142 00:05:08,428 --> 00:05:11,086 by four dimensional matrix. 143 00:05:11,086 --> 00:05:13,280 This is a four-dimensional vector, 144 00:05:13,280 --> 00:05:15,292 or a 4 x 1 matrix, and 145 00:05:15,292 --> 00:05:16,825 so the result of this, the 146 00:05:16,825 --> 00:05:18,210 result of this product is going 147 00:05:18,220 --> 00:05:20,881 to be a three-dimensional vector. 148 00:05:20,890 --> 00:05:23,169 Write, you know, the vector, 149 00:05:23,180 --> 00:05:26,531 with room for three elements. 150 00:05:26,531 --> 00:05:30,256 Let's do the, let's carry out the products. 151 00:05:30,256 --> 00:05:32,915 So for the first element, I'm 152 00:05:32,915 --> 00:05:35,068 going to take these four numbers 153 00:05:35,068 --> 00:05:36,272 and multiply them with the 154 00:05:36,272 --> 00:05:38,873 vector X. So I have 155 00:05:38,873 --> 00:05:42,227 1x1, plus 2x3, 156 00:05:42,568 --> 00:05:47,301 plus 1x2, plus 5x1, which 157 00:05:47,301 --> 00:05:49,994 is equal to - that's 158 00:05:50,050 --> 00:05:55,602 1+6, plus 2+6, which gives me 14. 159 00:05:55,630 --> 00:05:58,156 And then for the 160 00:05:58,156 --> 00:05:59,754 second element, I'm going 161 00:05:59,754 --> 00:06:01,422 to take this row now and 162 00:06:01,422 --> 00:06:04,604 multiply it with this vector (0x1)+3. 163 00:06:04,604 --> 00:06:06,196 All right, so 164 00:06:06,243 --> 00:06:12,764 0x1+ 3x3 plus 165 00:06:12,764 --> 00:06:19,958 0x2 plus 4x1, 166 00:06:20,840 --> 00:06:22,974 which is equal to, let's 167 00:06:22,974 --> 00:06:26,105 see that's 9+4, which is 13. 168 00:06:26,105 --> 00:06:28,093 And finally, for the last 169 00:06:28,093 --> 00:06:29,455 element, I'm going to take 170 00:06:29,455 --> 00:06:30,847 this last row, so I 171 00:06:30,847 --> 00:06:33,978 have minus one times one. 172 00:06:34,110 --> 00:06:38,068 You have minus two, or really there's a plus next to a two I guess. 173 00:06:38,080 --> 00:06:40,656 Times three plus zero 174 00:06:40,656 --> 00:06:42,441 times two plus zero times 175 00:06:42,441 --> 00:06:44,047 one, and so that's 176 00:06:44,047 --> 00:06:45,496 going to be minus one minus 177 00:06:45,496 --> 00:06:46,474 six, which is going to make 178 00:06:46,474 --> 00:06:49,636 this seven, and so that's vector seven. 179 00:06:49,636 --> 00:06:50,136 Okay? 180 00:06:50,136 --> 00:06:51,097 So my final answer is this 181 00:06:51,097 --> 00:06:54,033 vector fourteen, just to 182 00:06:54,033 --> 00:06:56,117 write to that without the colors, fourteen, 183 00:06:56,117 --> 00:06:59,843 thirteen, negative seven. 184 00:07:01,190 --> 00:07:03,567 And as promised, the 185 00:07:03,567 --> 00:07:07,775 result here is a three by one matrix. 186 00:07:07,775 --> 00:07:11,147 So that's how you multiply a matrix and a vector. 187 00:07:11,170 --> 00:07:12,309 I know that a lot just 188 00:07:12,309 --> 00:07:13,710 happened on this slide, so 189 00:07:13,710 --> 00:07:14,662 if you're not quite sure where all 190 00:07:14,680 --> 00:07:16,228 these numbers went, you know, 191 00:07:16,228 --> 00:07:17,260 feel free to pause the video 192 00:07:17,280 --> 00:07:18,345 you know, and so take a 193 00:07:18,345 --> 00:07:19,980 slow careful look at this 194 00:07:19,980 --> 00:07:21,195 big calculation that we just 195 00:07:21,195 --> 00:07:22,318 did and try to make 196 00:07:22,318 --> 00:07:23,755 sure that you understand the steps 197 00:07:23,760 --> 00:07:25,144 of what just happened to get 198 00:07:25,144 --> 00:07:29,570 us these numbers,fourteen, thirteen and eleven. 199 00:07:29,650 --> 00:07:31,959 Finally, let me show you a neat trick. 200 00:07:31,959 --> 00:07:33,939 Let's say we have 201 00:07:33,940 --> 00:07:36,462 a set of four houses so 4 202 00:07:36,462 --> 00:07:38,650 houses with 4 sizes like these. 203 00:07:38,650 --> 00:07:39,908 And let's say I have a 204 00:07:39,908 --> 00:07:41,418 hypotheses for predicting what is 205 00:07:41,420 --> 00:07:43,885 the price of a house, and 206 00:07:43,890 --> 00:07:45,861 let's say I want to compute, 207 00:07:45,861 --> 00:07:49,347 you know, H of X for each of my 4 houses here. 208 00:07:49,347 --> 00:07:51,039 It turns out there's neat way 209 00:07:51,039 --> 00:07:52,979 of posing this, applying this 210 00:07:52,980 --> 00:07:56,780 hypothesis to all of my houses at the same time. 211 00:07:56,780 --> 00:07:57,795 It turns out there's a neat 212 00:07:57,795 --> 00:07:59,509 way to pose this as a 213 00:07:59,509 --> 00:08:01,798 Matrix Vector multiplication. 214 00:08:02,240 --> 00:08:03,672 So, here's how I'm going to do it. 215 00:08:03,672 --> 00:08:06,717 I am going to construct a matrix as follows. 216 00:08:06,717 --> 00:08:08,122 My matrix is going to be 217 00:08:08,122 --> 00:08:11,892 1111 times, and I'm 218 00:08:11,892 --> 00:08:15,495 going to write down the sizes 219 00:08:15,510 --> 00:08:19,935 of my four houses here and 220 00:08:19,935 --> 00:08:21,249 I'm going to construct a vector 221 00:08:21,249 --> 00:08:23,354 as well, And my 222 00:08:23,354 --> 00:08:25,609 vector is going to this 223 00:08:25,609 --> 00:08:30,072 vector of two elements, that's 224 00:08:30,072 --> 00:08:32,182 minus 40 and 0.25. 225 00:08:32,182 --> 00:08:34,607 That's these two co-efficients; 226 00:08:34,607 --> 00:08:35,432 data 0 and data 1. 227 00:08:35,432 --> 00:08:36,835 And what I am going 228 00:08:36,835 --> 00:08:38,048 to do is to take matrix 229 00:08:38,060 --> 00:08:39,708 and that vector and multiply them 230 00:08:39,708 --> 00:08:42,465 together, that times is that multiplication symbol. 231 00:08:42,465 --> 00:08:43,288 So what do I get? 232 00:08:43,288 --> 00:08:46,412 Well this is a 233 00:08:46,420 --> 00:08:48,228 four by two matrix. 234 00:08:48,228 --> 00:08:52,005 This is a two by one matrix. 235 00:08:52,005 --> 00:08:53,952 So the outcome is going 236 00:08:53,952 --> 00:08:55,355 to be a four by one 237 00:08:55,355 --> 00:08:59,506 vector, all right. 238 00:08:59,520 --> 00:09:02,860 So, let me, 239 00:09:02,870 --> 00:09:05,334 so this is 240 00:09:05,334 --> 00:09:06,188 going to be a 4 by 241 00:09:06,188 --> 00:09:06,957 1 matrix is the outcome or 242 00:09:06,957 --> 00:09:10,035 really a four diminsonal vector, 243 00:09:10,035 --> 00:09:11,562 so let me write it as 244 00:09:11,562 --> 00:09:15,991 one of my four elements in my four real numbers here. 245 00:09:16,010 --> 00:09:17,202 Now it turns out and so 246 00:09:17,202 --> 00:09:18,952 this first element of this 247 00:09:18,952 --> 00:09:20,497 result, the way I 248 00:09:20,497 --> 00:09:21,505 am going to get that is, I 249 00:09:21,505 --> 00:09:25,526 am going to take this and multiply it by the vector. 250 00:09:25,526 --> 00:09:29,381 And so this is going to 251 00:09:29,381 --> 00:09:33,053 be -40 x 252 00:09:33,053 --> 00:09:37,645 1 + 4.25 x 2104. 253 00:09:37,645 --> 00:09:38,998 By the way, on 254 00:09:38,998 --> 00:09:40,915 the earlier slides I was 255 00:09:40,915 --> 00:09:42,257 writing 1 x -40 and 256 00:09:42,260 --> 00:09:44,405 2104 x 0.25, but 257 00:09:44,405 --> 00:09:46,570 the order doesn't matter, right? 258 00:09:46,580 --> 00:09:49,637 -40 x 1 is the same as 1 x -40. 259 00:09:49,637 --> 00:09:52,115 And this first element, of course, 260 00:09:52,115 --> 00:09:55,288 is "H" applied to 2104. 261 00:09:55,288 --> 00:09:57,395 So it's really the 262 00:09:57,395 --> 00:09:59,969 predicted price of my first house. 263 00:09:59,969 --> 00:10:02,351 Well, how about the second element? 264 00:10:02,390 --> 00:10:04,089 Hope you can see 265 00:10:04,089 --> 00:10:07,912 where I am going to get the second element. 266 00:10:07,912 --> 00:10:08,750 Right? 267 00:10:08,750 --> 00:10:11,052 I'm gonna take this and multiply it by my vector. 268 00:10:11,052 --> 00:10:13,154 And so that's gonna be 269 00:10:13,180 --> 00:10:15,038 -40 x 1 + 0.25 x 1416. 270 00:10:15,038 --> 00:10:23,037 And so this is going be "H" of 1416. 271 00:10:23,110 --> 00:10:23,110 Right? 272 00:10:25,810 --> 00:10:27,024 And so on for the 273 00:10:27,024 --> 00:10:30,720 third and the fourth 274 00:10:30,760 --> 00:10:33,797 elements of this 4 x 1 vector. 275 00:10:33,800 --> 00:10:37,142 And just there, right? 276 00:10:37,142 --> 00:10:39,239 This thing here that I 277 00:10:39,239 --> 00:10:41,131 just drew the green box around, 278 00:10:41,131 --> 00:10:42,752 that's a real number, OK? 279 00:10:42,752 --> 00:10:44,169 That's a single real number, 280 00:10:44,180 --> 00:10:45,673 and this thing here that 281 00:10:45,680 --> 00:10:47,812 I drew the magenta box around--the 282 00:10:47,812 --> 00:10:49,826 purple, magenta color box 283 00:10:49,850 --> 00:10:50,908 around--that's a real number, right? 284 00:10:50,920 --> 00:10:52,683 And so this thing on 285 00:10:52,683 --> 00:10:54,104 the right--this thing on the 286 00:10:54,104 --> 00:10:55,200 right overall, this is a 287 00:10:55,220 --> 00:10:59,288 4 by 1 dimensional matrix, was a 4 dimensional vector. 288 00:10:59,288 --> 00:11:00,728 And, the neat thing about 289 00:11:00,728 --> 00:11:02,128 this is that when you're 290 00:11:02,130 --> 00:11:04,613 actually implementing this in software--so 291 00:11:04,613 --> 00:11:06,344 when you have four houses and 292 00:11:06,350 --> 00:11:08,525 when you want to use your hypothesis 293 00:11:08,525 --> 00:11:12,308 to predict the prices, predict the price "Y" of all of these four houses. 294 00:11:12,308 --> 00:11:13,553 What this means is that, you 295 00:11:13,553 --> 00:11:16,130 know, you can write this in one line of code. 296 00:11:16,140 --> 00:11:17,878 When we talk about octave and 297 00:11:17,878 --> 00:11:19,782 program languages later, you can 298 00:11:19,790 --> 00:11:22,120 actually, you'll actually write this in one line of code. 299 00:11:22,120 --> 00:11:24,879 You write prediction equals my, 300 00:11:24,879 --> 00:11:29,697 you know, data matrix times 301 00:11:30,582 --> 00:11:33,888 parameters, right? 302 00:11:33,890 --> 00:11:36,994 Where data matrix is 303 00:11:36,994 --> 00:11:38,661 this thing here, and parameters 304 00:11:38,661 --> 00:11:40,447 is this thing here, and this 305 00:11:40,447 --> 00:11:44,138 times is a matrix vector multiplication. 306 00:11:44,138 --> 00:11:45,834 And if you just do this then 307 00:11:45,834 --> 00:11:47,579 this variable prediction - sorry 308 00:11:47,579 --> 00:11:49,270 for my bad handwriting - then 309 00:11:49,270 --> 00:11:50,942 just implement this one 310 00:11:50,942 --> 00:11:52,357 line of code assuming you have 311 00:11:52,357 --> 00:11:55,328 an appropriate library to do matrix vector multiplication. 312 00:11:55,328 --> 00:11:56,518 If you just do this, 313 00:11:56,518 --> 00:11:58,965 then prediction becomes this 314 00:11:58,965 --> 00:12:00,714 4 by 1 dimensional vector, on 315 00:12:00,714 --> 00:12:04,655 the right, that just gives you all the predicted prices. 316 00:12:04,655 --> 00:12:07,163 And your alternative to doing 317 00:12:07,163 --> 00:12:09,286 this as a matrix vector multiplication 318 00:12:09,310 --> 00:12:11,241 would be to write eomething like 319 00:12:11,241 --> 00:12:13,542 , you know, for I equals 1 to 4, right? 320 00:12:13,542 --> 00:12:15,150 And you have say a thousand houses 321 00:12:15,160 --> 00:12:17,451 it would be for I equals 1 to a thousand or whatever. 322 00:12:17,451 --> 00:12:18,772 And then you have to write a 323 00:12:18,772 --> 00:12:21,898 prediction, you know, if I equals. 324 00:12:21,910 --> 00:12:23,123 and then do a bunch 325 00:12:23,130 --> 00:12:25,645 more work over there and it 326 00:12:25,645 --> 00:12:27,188 turns out that When you 327 00:12:27,188 --> 00:12:28,549 have a large number of houses, 328 00:12:28,549 --> 00:12:29,928 if you're trying to predict the prices 329 00:12:29,930 --> 00:12:31,033 of not just four but maybe 330 00:12:31,033 --> 00:12:33,230 of a thousand houses then 331 00:12:33,410 --> 00:12:35,175 it turns out that when 332 00:12:35,175 --> 00:12:36,118 you implement this in the 333 00:12:36,118 --> 00:12:40,087 computer, implementing it like this, in any of the various languages. 334 00:12:40,087 --> 00:12:41,535 This is not only true for 335 00:12:41,535 --> 00:12:43,022 Octave, but for Supra Server 336 00:12:43,030 --> 00:12:46,252 Java or Python, other high-level, other languages as well. 337 00:12:46,252 --> 00:12:48,045 It turns out, that, by writing 338 00:12:48,045 --> 00:12:49,811 code in this style on the 339 00:12:49,811 --> 00:12:51,552 left, it allows you to 340 00:12:51,552 --> 00:12:53,283 not only simplify the 341 00:12:53,283 --> 00:12:54,677 code, because, now, you're just 342 00:12:54,677 --> 00:12:55,857 writing one line of code 343 00:12:55,870 --> 00:12:58,427 rather than the form of a bunch of things inside. 344 00:12:58,450 --> 00:12:59,727 But, for subtle reasons, that we 345 00:12:59,730 --> 00:13:01,398 will see later, it turns 346 00:13:01,400 --> 00:13:03,392 out to be much more computationally 347 00:13:03,392 --> 00:13:05,617 efficient to make predictions 348 00:13:05,617 --> 00:13:06,583 on all of the prices of 349 00:13:06,583 --> 00:13:08,348 all of your houses doing it 350 00:13:08,360 --> 00:13:09,693 the way on the left than the 351 00:13:09,693 --> 00:13:13,334 way on the right than if you were to write your own formula. 352 00:13:13,334 --> 00:13:14,596 I'll say more about this 353 00:13:14,596 --> 00:13:15,978 later when we talk about 354 00:13:15,978 --> 00:13:17,684 vectorization, but, so, by 355 00:13:17,684 --> 00:13:19,145 posing a prediction this way, you 356 00:13:19,145 --> 00:13:20,511 get not only a simpler piece 357 00:13:20,511 --> 00:13:23,200 of code, but a more efficient one. 358 00:13:23,200 --> 00:13:25,151 So, that's it for 359 00:13:25,151 --> 00:13:27,063 matrix vector multiplication and we'll 360 00:13:27,063 --> 00:13:28,432 make good use of these sorts 361 00:13:28,432 --> 00:13:30,352 of operations as we develop 362 00:13:30,370 --> 00:13:32,888 the living regression in other models further. 363 00:13:32,910 --> 00:13:34,259 But, in the next video we're 364 00:13:34,259 --> 00:13:36,150 going to take this and generalize this 365 00:13:36,150 --> 00:13:39,527 to the case of matrix matrix multiplication.