forked from fengdu78/Coursera-ML-AndrewNg-Notes
-
Notifications
You must be signed in to change notification settings - Fork 0
/
3 - 2 - Addition and Scalar Multiplication (7 min).srt
886 lines (709 loc) · 16 KB
/
3 - 2 - Addition and Scalar Multiplication (7 min).srt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
1
00:00:00,250 --> 00:00:01,612
In this video we'll talk about
在这段视频中
(字幕整理:中国海洋大学 黄海广,[email protected] )
2
00:00:01,612 --> 00:00:03,503
matrix addition and subtraction,
我们将讨论矩阵的加法和减法运算
3
00:00:03,503 --> 00:00:04,950
as well as how to
以及如何进行
4
00:00:04,950 --> 00:00:06,582
multiply a matrix by a
数和矩阵的乘法
5
00:00:06,582 --> 00:00:09,292
number, also called Scalar Multiplication.
也就是标量乘法
6
00:00:09,292 --> 00:00:11,825
Let's start an example.
让我们从下面这个例子开始
7
00:00:11,825 --> 00:00:14,725
Given two matrices like these,
假设有这样两个矩阵
8
00:00:14,725 --> 00:00:16,735
let's say I want to add them together.
如果想对它们做求和运算
9
00:00:16,735 --> 00:00:18,038
How do I do that?
应该怎么做呢?
10
00:00:18,038 --> 00:00:20,538
And so, what does addition of matrices mean?
或者说 矩阵的加法到底是如何进行的?
11
00:00:20,538 --> 00:00:21,632
It turns out that if you
答案是
12
00:00:21,632 --> 00:00:24,312
want to add two matrices, what
如果你想将两个矩阵相加
13
00:00:24,312 --> 00:00:25,762
you do is you just add
你只需要将这两个矩阵的
14
00:00:25,762 --> 00:00:28,076
up the elements of these matrices one at a time.
每一个元素都逐个相加
15
00:00:28,076 --> 00:00:30,363
So, my result of adding
因此 两个矩阵相加
16
00:00:30,363 --> 00:00:31,480
two matrices is going to
所得到的结果
17
00:00:31,480 --> 00:00:33,415
be itself another matrix and
就是一个新的矩阵
18
00:00:33,415 --> 00:00:34,972
the first element again just by
它的第一个元素
19
00:00:34,972 --> 00:00:36,732
taking one and four and
是1和4相加的结果
20
00:00:36,732 --> 00:00:39,470
multiplying them and adding them together, so I get five.
因此我们得到5
21
00:00:39,470 --> 00:00:41,578
The second element I get
接下来是第二个元素
22
00:00:41,578 --> 00:00:43,092
by taking two and two
用2和2相加
23
00:00:43,092 --> 00:00:44,169
and adding them, so I get
因此得到4
24
00:00:44,169 --> 00:00:47,240
four; three plus three
然后是3加0得到3
25
00:00:47,255 --> 00:00:49,568
plus zero is three, and so on.
以此类推
26
00:00:49,570 --> 00:00:51,442
I'm going to stop changing colors, I guess.
这里我用不同颜色区别一下
27
00:00:51,442 --> 00:00:52,768
And, on the right is open
接下来右边这一列元素
28
00:00:52,768 --> 00:00:54,820
five, ten and two.
就是0.5 10和2
29
00:00:56,140 --> 00:00:57,182
And it turns out you can
这里大家不难发现
30
00:00:57,182 --> 00:01:00,408
add only two matrices that are of the same dimensions.
只有相同维度的两个矩阵才能相加
31
00:01:00,408 --> 00:01:02,789
So this example is
对于这个例子而言
32
00:01:02,789 --> 00:01:05,595
a three by two matrix,
这是一个3行2列的矩阵
33
00:01:07,120 --> 00:01:09,029
because this has 3
也就是说矩阵的行数为3
34
00:01:09,029 --> 00:01:11,917
rows and 2 columns, so it's 3 by 2.
列数是2 因此是3行2列
35
00:01:11,917 --> 00:01:13,451
This is also a 3
第二个矩阵
36
00:01:13,451 --> 00:01:15,113
by 2 matrix, and the
也是一个3行2列的矩阵
37
00:01:15,113 --> 00:01:16,202
result of adding these two
因此这两个矩阵相加的结果
38
00:01:16,202 --> 00:01:19,415
matrices is a 3 by 2 matrix again.
也是一个3行2列的矩阵
39
00:01:19,415 --> 00:01:20,468
So you can only add
所以你只能将相同维度的矩阵
40
00:01:20,470 --> 00:01:21,837
matrices of the same
进行相加运算
41
00:01:21,837 --> 00:01:23,533
dimension, and the result
同时 所得到的结果
42
00:01:23,550 --> 00:01:24,959
will be another matrix that's of
将会是一个新的矩阵
43
00:01:24,959 --> 00:01:28,057
the same dimension as the ones you just added.
这个矩阵与相加的两个矩阵维度相同
44
00:01:29,180 --> 00:01:30,785
Where as in contrast, if you
反过来
45
00:01:30,785 --> 00:01:31,803
were to take these two matrices, so this
如果你想将这样两个矩阵相加
46
00:01:31,803 --> 00:01:32,894
one is a 3 by
这是一个3行2列的矩阵
47
00:01:32,894 --> 00:01:36,208
2 matrix, okay, 3 rows, 2 columns.
行数为3 列数为2
48
00:01:36,230 --> 00:01:38,659
This here is a 2 by 2 matrix.
而这一个是2行2列的矩阵
49
00:01:39,190 --> 00:01:41,190
And because these two matrices
那么由于这两个矩阵
50
00:01:41,200 --> 00:01:42,837
are not of the same dimension,
维度是不相同的
51
00:01:43,160 --> 00:01:44,635
you know, this is an error,
这就出现错误了
52
00:01:44,635 --> 00:01:46,400
so you cannot add these
所以我们不能将它们相加
53
00:01:46,430 --> 00:01:48,508
two matrices and, you know,
也就是说
54
00:01:48,508 --> 00:01:52,184
their sum is not well-defined.
这两个矩阵的和是没有意义的
55
00:01:52,642 --> 00:01:54,561
So that's matrix addition.
这就是矩阵的加法运算
56
00:01:54,561 --> 00:01:58,382
Next, let's talk about multiplying matrices by a scalar number.
接下来 我们讨论矩阵和标量的乘法运算
57
00:01:58,382 --> 00:02:00,069
And the scalar is just a,
这里所说的标量
58
00:02:00,069 --> 00:02:02,028
maybe a overly fancy term for,
可能是一个复杂的结构
59
00:02:02,028 --> 00:02:04,342
you know, a number or a real number.
或者只是一个简单的数字 或者说实数
60
00:02:04,760 --> 00:02:07,075
Alright, this means real number.
标量在这里指的就是实数
61
00:02:07,076 --> 00:02:10,280
So let's take the number 3 and multiply it by this matrix.
如果我们用数字3来和这个矩阵相乘
62
00:02:10,280 --> 00:02:13,182
And if you do that, the result is pretty much what you'll expect.
那么结果是显而易见的
63
00:02:13,182 --> 00:02:14,926
You just take your elements
你只需要将矩阵中的所有元素
64
00:02:14,926 --> 00:02:16,184
of the matrix and multiply
都和3相乘
65
00:02:16,184 --> 00:02:18,114
them by 3, one at a time.
每一个都逐一与3相乘
66
00:02:18,114 --> 00:02:19,428
So, you know, one
因此 1和3相乘
67
00:02:19,428 --> 00:02:21,708
times three is three.
结果是3
68
00:02:21,708 --> 00:02:24,011
What, two times three is
2和3相乘
69
00:02:24,011 --> 00:02:25,988
six, 3 times 3
结果是6
70
00:02:25,988 --> 00:02:28,181
is 9, and let's see, I'm
最后3乘以3得9
71
00:02:28,181 --> 00:02:30,152
going to stop changing colors again.
我再换一下颜色
72
00:02:30,157 --> 00:02:31,654
Zero times 3 is zero.
0乘以3得0
73
00:02:31,654 --> 00:02:35,992
Three times 5 is 15, and 3 times 1 is three.
3乘以5得15 最后3乘以1得3
74
00:02:35,992 --> 00:02:37,849
And so this matrix is the
这样得到的这个矩阵
75
00:02:37,849 --> 00:02:40,702
result of multiplying that matrix on the left by 3.
就是左边这个矩阵和3相乘的结果
76
00:02:40,702 --> 00:02:42,173
And you notice, again,
我们再次注意到
77
00:02:42,173 --> 00:02:43,443
this is a 3 by 2
这是一个3行2列的矩阵
78
00:02:43,443 --> 00:02:44,903
matrix and the result is
得到的结果矩阵
79
00:02:44,903 --> 00:02:47,505
a matrix of the same dimension.
维度也是相同的
80
00:02:47,505 --> 00:02:48,634
This is a 3 by
也就是说这两个矩阵
81
00:02:48,634 --> 00:02:49,920
2, both of these are
都是3行2列
82
00:02:49,920 --> 00:02:52,607
3 by 2 dimensional matrices.
这也是3行2列
83
00:02:52,634 --> 00:02:54,334
And by the way,
顺便说一下
84
00:02:54,334 --> 00:02:57,050
you can write multiplication, you know, either way.
你也可以写成另一种方式
85
00:02:57,050 --> 00:02:59,491
So, I have three times this matrix.
这里是3和这个矩阵相乘
86
00:02:59,491 --> 00:03:01,468
I could also have written this
你也可以把这个矩阵写在前面
87
00:03:01,470 --> 00:03:05,256
matrix and 0, 2, 5, 3, 1, right.
1 0 2 5 3 1
88
00:03:05,256 --> 00:03:07,672
I just copied this matrix over to the right.
把左边这个矩阵照抄过来
89
00:03:07,672 --> 00:03:11,228
I can also take this matrix and multiply this by three.
我们也可以用这个矩阵乘以3
90
00:03:11,228 --> 00:03:12,040
So whether it's you know, 3
也就是说
91
00:03:12,060 --> 00:03:13,388
times the matrix or the
3乘以这个矩阵
92
00:03:13,388 --> 00:03:14,983
matrix times three is
和这个矩阵乘以3
93
00:03:14,983 --> 00:03:18,771
the same thing and this thing here in the middle is the result.
结果都是一回事 都是中间的这个矩阵
94
00:03:19,380 --> 00:03:22,869
You can also take a matrix and divide it by a number.
你也可以用矩阵除以一个数
95
00:03:22,869 --> 00:03:24,275
So, turns out taking
那么 我们可以看到
96
00:03:24,275 --> 00:03:25,716
this matrix and dividing it by
用这个矩阵除以4
97
00:03:25,716 --> 00:03:27,140
four, this is actually the
实际上就是
98
00:03:27,172 --> 00:03:29,055
same as taking the number
用四分之一
99
00:03:29,055 --> 00:03:32,819
one quarter, and multiplying it by this matrix.
来和这个矩阵相乘
100
00:03:32,819 --> 00:03:35,318
4, 0, 6, 3 and
4 0 6 3
101
00:03:35,318 --> 00:03:36,803
so, you can figure
不难发现
102
00:03:36,820 --> 00:03:38,593
the answer, the result of
相乘的结果是
103
00:03:38,593 --> 00:03:40,365
this product is, one quarter
1/4和4相乘为1
104
00:03:40,365 --> 00:03:43,274
times four is one, one quarter times zero is zero.
1/4和0相乘得0
105
00:03:43,282 --> 00:03:46,570
One quarter times six is,
1/4乘以6
106
00:03:46,590 --> 00:03:49,353
what, three halves, about six over
结果是3/2
107
00:03:49,353 --> 00:03:50,369
four is three halves, and
6/4也就是3/2
108
00:03:50,369 --> 00:03:53,862
one quarter times three is three quarters.
最后1/4乘以3得3/4
109
00:03:54,410 --> 00:03:55,880
And so that's the results
这样我们就得到了
110
00:03:55,920 --> 00:03:59,207
of computing this matrix divided by four.
这个矩阵除以4的结果
111
00:03:59,207 --> 00:04:01,677
Vectors give you the result.
结果就是是右边这个矩阵
112
00:04:01,697 --> 00:04:03,805
Finally, for a slightly
最后
113
00:04:03,805 --> 00:04:05,714
more complicated example, you can
我们来看一个稍微复杂一点的例子
114
00:04:05,714 --> 00:04:09,460
also take these operations and combine them together.
我们可以把所有这些运算结合起来
115
00:04:09,513 --> 00:04:11,448
So in this calculation, I
在这个运算中
116
00:04:11,448 --> 00:04:12,801
have three times a vector
需要用3来乘以这个向量
117
00:04:12,801 --> 00:04:16,370
plus a vector minus another vector divided by three.
然后加上一个向量 再减去另一个向量除以3的结果
118
00:04:16,370 --> 00:04:18,344
So just make sure we know where these are, right.
让我们先来整理一下这几项运算
119
00:04:18,344 --> 00:04:20,031
This multiplication.
首先第一个运算
120
00:04:20,031 --> 00:04:23,648
This is an example of
很明显这是标量乘法的例子
121
00:04:23,680 --> 00:04:27,986
scalar multiplication because I am taking three and multiplying it.
因为这里是用3来乘以一个矩阵
122
00:04:27,986 --> 00:04:30,240
And this is, you know, another
然后这一项
123
00:04:30,240 --> 00:04:32,067
scalar multiplication.
很显然这是另一个标量乘法
124
00:04:32,067 --> 00:04:34,182
Or more like scalar division, I guess.
或者可以叫标量除法
125
00:04:34,182 --> 00:04:36,503
It really just means one zero times this.
其实也就是1/3乘以这个矩阵
126
00:04:36,503 --> 00:04:39,445
And so if we evaluate
因此
127
00:04:39,509 --> 00:04:43,044
these two operations first, then
如果我们先考虑这两项运算
128
00:04:43,044 --> 00:04:44,612
what we get is this thing
那么我们将得到的是
129
00:04:44,612 --> 00:04:47,127
is equal to, let's see,
我们看一下
130
00:04:47,127 --> 00:04:49,902
so three times that vector is three,
3乘以这个矩阵
131
00:04:49,912 --> 00:04:53,200
twelve, six, plus
结果是3 12 6
132
00:04:53,200 --> 00:04:55,088
my vector in the middle which
然后和中间的矩阵相加
133
00:04:55,088 --> 00:04:58,552
is a 005 minus
也就是0 0 5
134
00:04:59,850 --> 00:05:03,733
one, zero, two-thirds, right?
最后再减去1 0 2/3
135
00:05:03,740 --> 00:05:05,318
And again, just to make
同样地 为了便于理解
136
00:05:05,318 --> 00:05:07,064
sure we understand what is going on here,
我们再来梳理一下这几项
137
00:05:07,064 --> 00:05:11,504
this plus symbol, that is
这里的这个加号
138
00:05:11,520 --> 00:05:15,690
matrix addition, right?
表明这是一个矩阵加法 对吧?
139
00:05:15,690 --> 00:05:16,973
I really, since these are
当然这里是向量
140
00:05:16,973 --> 00:05:20,204
vectors, remember, vectors are special cases of matrices, right?
别忘了 向量是特殊的矩阵 对吧?
141
00:05:20,204 --> 00:05:21,538
This, you can also call
或者你也可以称之为
142
00:05:21,538 --> 00:05:25,106
this vector addition This
向量加法运算
143
00:05:25,110 --> 00:05:27,148
minus sign here, this is
同样 这里的减号表明
144
00:05:27,160 --> 00:05:30,162
again a matrix subtraction,
这是一个矩阵减法运算
145
00:05:30,162 --> 00:05:32,249
but because this is an
但由于这是一个n行1列的矩阵
146
00:05:32,249 --> 00:05:33,432
n by 1, really a three
实际上是3行1列
147
00:05:33,432 --> 00:05:35,547
by one matrix, that this
因此这个矩阵
148
00:05:35,547 --> 00:05:36,494
is actually a vector, so this is
实际上是也一个向量
149
00:05:36,494 --> 00:05:39,822
also vector, this column.
一个列向量
150
00:05:39,850 --> 00:05:43,677
We call this matrix a vector subtraction, as well.
因此也可以把它称作向量的减法运算
151
00:05:43,677 --> 00:05:44,392
OK?
好了!
152
00:05:44,392 --> 00:05:46,073
And finally to wrap this up.
最后再整理一下
153
00:05:46,110 --> 00:05:48,103
This therefore gives me a
最终的结果依然是一个向量
154
00:05:48,118 --> 00:05:49,952
vector, whose first element is
向量的第一个元素
155
00:05:49,952 --> 00:05:53,632
going to be 3+0-1,
是3+0-1
156
00:05:53,632 --> 00:05:56,150
so that's 3-1, which is 2.
就是3-1 也就是2
157
00:05:56,150 --> 00:06:01,204
The second element is 12+0-0, which is 12.
第二个元素是12+0-0 也就是12
158
00:06:01,214 --> 00:06:03,970
And the third element
最后第三个元素
159
00:06:03,970 --> 00:06:07,222
of this is, what, 6+5-(2/3),
6+5-(2/3)
160
00:06:07,222 --> 00:06:10,678
which is 11-(2/3), so
也就是11-(2/3)
161
00:06:10,678 --> 00:06:14,021
that's 10 and one-third
结果是10又三分之一
162
00:06:14,021 --> 00:06:16,029
and see, you close this square bracket.
关闭右括号
163
00:06:16,029 --> 00:06:17,983
And so this gives me a
我们得到了最终的结果
164
00:06:17,983 --> 00:06:21,671
3 by 1 matrix, which is
这是一个3行1列的矩阵
165
00:06:21,671 --> 00:06:23,901
also just called a 3
或者也可以说是
166
00:06:23,901 --> 00:06:29,005
dimensional vector, which
一个维度为3的向量
167
00:06:29,030 --> 00:06:32,847
is the outcome of this calculation over here.
这就是这个运算式的计算结果
168
00:06:32,847 --> 00:06:34,984
So that's how you
所以
169
00:06:34,984 --> 00:06:36,698
add and subtract matrices and
你学会了矩阵或向量的加减运算
170
00:06:36,698 --> 00:06:41,488
vectors and multiply them by scalars or by row numbers.
以及矩阵或向量跟标量 或者说实数 的乘法运算
171
00:06:41,488 --> 00:06:42,767
So far I have only talked
到目前为止
172
00:06:42,767 --> 00:06:44,718
about how to multiply matrices and
我只介绍了如何进行
173
00:06:44,718 --> 00:06:46,994
vectors by scalars, by row numbers.
矩阵或向量与数的乘法运算
174
00:06:46,994 --> 00:06:48,128
In the next video we will
在下一讲中
175
00:06:48,128 --> 00:06:49,418
talk about a much more
我们将讨论一个更有趣的话题
176
00:06:49,418 --> 00:06:51,035
interesting step, of taking
那就是如何进行
177
00:06:51,035 --> 00:06:54,112
2 matrices and multiplying 2 matrices together.
两个矩阵的乘法运算