1
00:00:00,050 --> 00:00:03,980
Welcome to the section in which we will look at linear algebra operations.

2
00:00:03,980 --> 00:00:06,980
So just right here we have TensorFlow Linalg.

3
00:00:06,980 --> 00:00:12,440
And the very first operation we'll be looking at will be that of the matrix multiplication.

4
00:00:12,440 --> 00:00:15,110
So right here we have matmul.

5
00:00:15,320 --> 00:00:20,120
Essentially what this matrix multiplication does is it takes in two matrices.

6
00:00:20,180 --> 00:00:25,970
And then um computes the matrix multiplication of those two matrices.

7
00:00:25,970 --> 00:00:29,000
So here we have TensorFlow Linalg matmul.

8
00:00:29,000 --> 00:00:31,040
And let's just copy this part.

9
00:00:31,280 --> 00:00:32,390
There we go.

10
00:00:32,390 --> 00:00:36,860
And then we have this um examples which we have right here.

11
00:00:37,010 --> 00:00:39,050
So let's go ahead and test this out.

12
00:00:39,050 --> 00:00:43,640
We have ab AB take this off.

13
00:00:43,640 --> 00:00:48,650
And then let's set a let's get back up here and try to copy this.

14
00:00:48,650 --> 00:00:49,580
There we go.

15
00:00:49,580 --> 00:00:51,410
We have let's say this is a.

16
00:00:51,650 --> 00:00:53,540
So this is our a.

17
00:00:54,930 --> 00:00:55,380
Yeah.

18
00:00:55,380 --> 00:01:03,330
We have a and then we have um well that's a and then we have B, which is going to be the same as a.

19
00:01:03,330 --> 00:01:09,360
So let's copy this paste out here we have A and B which are exact same.

20
00:01:09,360 --> 00:01:10,380
So that's it.

21
00:01:10,380 --> 00:01:16,260
Now let's um b now let's go ahead and print this output out.

22
00:01:16,260 --> 00:01:21,840
We have print out the map or matrix multiplication of A and b.

23
00:01:21,840 --> 00:01:23,730
So let's run that and see what we get.

24
00:01:23,730 --> 00:01:25,050
You see we have this error.

25
00:01:25,050 --> 00:01:29,160
So we have uh matrix size incompatible.

26
00:01:29,160 --> 00:01:31,950
Now the reason why we're having this is simple.

27
00:01:31,950 --> 00:01:33,840
Let's first of all print out a shape.

28
00:01:33,840 --> 00:01:39,360
And then we print out B shape C here we have 4545.

29
00:01:39,360 --> 00:01:46,710
Now if you um are new to this um matrix multiplication and linear algebra in general, you should take

30
00:01:46,710 --> 00:01:54,690
note of the fact that when multiplying two matrices, the number of columns of the first matrix will

31
00:01:54,690 --> 00:01:57,840
or should always match the number of rows of the second matrix.

32
00:01:57,840 --> 00:02:02,970
So when you have a matrix like, um, or when you have two matrix like A and B, where this there is

33
00:02:02,970 --> 00:02:03,780
no match.

34
00:02:03,780 --> 00:02:05,790
That's why you have this kind of error.

35
00:02:05,790 --> 00:02:08,250
So let's, let's um, try to solve this problem.

36
00:02:08,250 --> 00:02:12,360
Let's, let's say we change this from five columns to four columns.

37
00:02:12,360 --> 00:02:15,540
Or we could change this from five four rows to five rows.

38
00:02:15,540 --> 00:02:18,420
So b here let's copy this.

39
00:02:18,420 --> 00:02:20,190
Increase number of rows.

40
00:02:20,460 --> 00:02:22,020
Take this off.

41
00:02:22,590 --> 00:02:23,760
Increase number of rows.

42
00:02:23,760 --> 00:02:25,230
And that's it okay.

43
00:02:25,230 --> 00:02:30,720
So now you see it's going to work because we have four by five and five by five.

44
00:02:30,720 --> 00:02:32,760
And this is our output.

45
00:02:33,150 --> 00:02:40,230
Now it should be noted that if instead of um um the math model of A and B, we try to print out, we

46
00:02:40,230 --> 00:02:45,150
try to print out A times B like this, you would find that we'll get an error.

47
00:02:45,150 --> 00:02:47,310
So the math model produces no error.

48
00:02:47,310 --> 00:02:49,140
But A times B produces an error.

49
00:02:49,140 --> 00:02:51,210
Again here we have incompatible shapes.

50
00:02:51,210 --> 00:02:57,540
Now the reason why we're having this is because with this A times B it's an element wise multiplication.

51
00:02:57,540 --> 00:02:59,850
That is we're going element by element.

52
00:02:59,850 --> 00:03:00,750
That's three.

53
00:03:00,750 --> 00:03:04,470
And this corresponding here we multiply this one and this corresponding.

54
00:03:04,470 --> 00:03:06,360
Here we multiply this nine.

55
00:03:06,360 --> 00:03:08,940
With this corresponding we multiply and so on and so forth.

56
00:03:09,270 --> 00:03:16,680
Uh, and so if we have this tool or matrices which do not have the exact same shape, or where we cannot

57
00:03:16,680 --> 00:03:22,200
even broadcast one to uh, given shape, then we would have an error.

58
00:03:22,200 --> 00:03:25,110
So you could see clearly why we get an an error.

59
00:03:25,110 --> 00:03:30,660
Because, um, if we're trying to compare this seven year or we're trying to multiply the seven which

60
00:03:30,660 --> 00:03:34,080
is corresponding, and a, we're not going to have that corresponding value.

61
00:03:34,080 --> 00:03:36,330
And so that's why we get this error.

62
00:03:36,330 --> 00:03:38,370
And so in that case this will work.

63
00:03:38,370 --> 00:03:39,570
Let's get back here.

64
00:03:39,570 --> 00:03:42,630
This will work if um we take this off.

65
00:03:42,630 --> 00:03:46,740
So if we take this off and run that you would find that we have no error.

66
00:03:46,740 --> 00:03:51,030
So obviously we have three times three like this.

67
00:03:51,030 --> 00:03:52,500
Three times three is nine.

68
00:03:52,500 --> 00:03:54,150
So that's why we have nine here.

69
00:03:54,690 --> 00:04:00,510
Uh right here then if we take some random position this two times two, we have four.

70
00:04:00,540 --> 00:04:01,830
That's why we have four right here.

71
00:04:01,830 --> 00:04:02,520
So that's it.

72
00:04:02,520 --> 00:04:08,970
Now let's take this let's comment this get back to our linear or linear model.

73
00:04:08,970 --> 00:04:10,500
We get an error.

74
00:04:10,500 --> 00:04:15,600
That's obviously because the number of columns for the first doesn't match the number of rows for the

75
00:04:15,600 --> 00:04:16,020
second.

76
00:04:16,020 --> 00:04:19,140
So again we're going to copy this and paste our year.

77
00:04:19,140 --> 00:04:20,250
Run that again.

78
00:04:20,250 --> 00:04:21,960
And now everything should be fine.

79
00:04:21,960 --> 00:04:23,610
Now let's keep let's make this simpler.

80
00:04:23,610 --> 00:04:27,660
So we could explain uh matrix multiplication in simple terms.

81
00:04:27,900 --> 00:04:29,340
Let's take this off.

82
00:04:29,790 --> 00:04:31,500
Take three by three.

83
00:04:32,220 --> 00:04:33,840
So we'll have three by three here.

84
00:04:33,840 --> 00:04:35,820
And here we want to have two by three.

85
00:04:35,820 --> 00:04:38,670
So let's, let's just two by three.

86
00:04:38,670 --> 00:04:39,780
That's two rows.

87
00:04:40,350 --> 00:04:45,000
Take that off and then by three that's fine.

88
00:04:45,000 --> 00:04:47,970
So let's run that again and see what we what we get.

89
00:04:47,970 --> 00:04:52,260
So you see that works two by three three by three it produces two by three.

90
00:04:52,260 --> 00:04:55,800
Now let's take this example and show you how we get the output.

91
00:04:55,800 --> 00:04:58,890
So right here we have this input which is two by three.

92
00:04:59,760 --> 00:05:01,470
Or we have a which is two by three.

93
00:05:01,470 --> 00:05:03,510
And we have b which is three by three.

94
00:05:03,630 --> 00:05:06,690
And then the way we get the outputs is simple.

95
00:05:06,690 --> 00:05:10,560
We take one times three plus five.

96
00:05:10,560 --> 00:05:17,400
That's it here this one one times three plus five.

97
00:05:18,610 --> 00:05:20,320
Times zero.

98
00:05:20,870 --> 00:05:23,930
Plus one times one.

99
00:05:24,170 --> 00:05:24,770
You see that?

100
00:05:24,770 --> 00:05:27,350
And then we get the we we put the output here.

101
00:05:27,350 --> 00:05:31,550
So now we have one times three which is three plus five times zero which is zero.

102
00:05:31,550 --> 00:05:33,680
So we have three plus zero.

103
00:05:33,680 --> 00:05:37,160
So we have three plus zero.

104
00:05:37,160 --> 00:05:40,070
And then we have one times one which is one plus one.

105
00:05:40,070 --> 00:05:42,080
So that's how we get this first position.

106
00:05:42,380 --> 00:05:46,190
Then for the next position let's let's bundle this up.

107
00:05:46,190 --> 00:05:47,750
So that's for the first position.

108
00:05:47,750 --> 00:05:51,200
For the next position we have again one times one.

109
00:05:51,860 --> 00:05:56,450
Plus five times one plus one times five.

110
00:05:57,000 --> 00:06:01,200
So one times one is one, five times one is five.

111
00:06:01,200 --> 00:06:05,760
So we have one plus five plus one times five which is five.

112
00:06:05,760 --> 00:06:07,290
So plus five again.

113
00:06:07,650 --> 00:06:11,130
And that's how we we obtain all those different values.

114
00:06:11,130 --> 00:06:15,390
So we could bond those bundle this other one up one times nine.

115
00:06:15,630 --> 00:06:22,710
Um is nine five times seven is um 3535 plus nine is 44.

116
00:06:23,190 --> 00:06:24,660
Um well let's just put that out.

117
00:06:24,660 --> 00:06:30,570
So we have nine, nine plus 35 and then plus one.

118
00:06:30,570 --> 00:06:32,490
So nine plus 35.

119
00:06:33,440 --> 00:06:34,970
Plus one.

120
00:06:35,750 --> 00:06:36,710
That's fine.

121
00:06:36,710 --> 00:06:43,820
Now for the next, um, we have seven times 321 plus zero.

122
00:06:43,820 --> 00:06:46,430
So we have 21 plus zero plus zero.

123
00:06:46,430 --> 00:06:49,010
So we have essentially here we have 21.

124
00:06:49,010 --> 00:06:57,380
And then for the next we have seven times one um which is seven plus three plus zero.

125
00:06:57,380 --> 00:07:00,830
So seven times one seven plus three plus zero that's ten.

126
00:07:00,830 --> 00:07:03,200
And then for the next we have seven times nine.

127
00:07:03,200 --> 00:07:12,140
So here we have seven times nine which is 63 plus um 2163 plus 21.

128
00:07:12,140 --> 00:07:13,280
That's 84.

129
00:07:13,280 --> 00:07:15,500
So here we have 84 plus zero.

130
00:07:15,500 --> 00:07:17,210
So here we have 84.

131
00:07:17,210 --> 00:07:19,820
So finally we will have this output which is three.

132
00:07:20,240 --> 00:07:23,540
Uh from here we will have um 11.

133
00:07:23,960 --> 00:07:30,620
We will have um 30 or 45 will have 21.

134
00:07:31,470 --> 00:07:34,680
Ten and then 84.

135
00:07:34,680 --> 00:07:35,790
So that's it.

136
00:07:35,790 --> 00:07:36,930
And then 84.

137
00:07:37,580 --> 00:07:40,250
Getting back to the code, you could verify that.

138
00:07:40,250 --> 00:07:45,140
You see here we have 411, 45, 21, ten and 84.

139
00:07:46,130 --> 00:07:48,200
Um, this actually four, three plus one is four.

140
00:07:48,200 --> 00:07:49,430
So that was an error.

141
00:07:49,430 --> 00:07:50,630
So here we have four.

142
00:07:50,660 --> 00:07:51,320
That's it.

143
00:07:51,710 --> 00:07:56,150
Um, we we now understand how we get this output, which is quite simple.

144
00:07:56,510 --> 00:07:59,870
And also we could get the shape before the calculations.

145
00:07:59,870 --> 00:08:03,320
Now notice how because these two are the same.

146
00:08:03,680 --> 00:08:05,540
See these two are the same.

147
00:08:05,930 --> 00:08:10,640
The output is this outer um dimensions.

148
00:08:10,640 --> 00:08:14,180
So the number of rows here will be the number of rows of the output.

149
00:08:14,180 --> 00:08:17,750
And the number of columns here will be will be the number of columns of the output.

150
00:08:17,750 --> 00:08:23,150
So here we have two by three two by three output.

151
00:08:23,150 --> 00:08:24,710
Because here we have two rows.

152
00:08:24,710 --> 00:08:26,600
And here we have three columns.

153
00:08:26,600 --> 00:08:28,250
And these two obviously must match.

154
00:08:28,250 --> 00:08:34,160
Also notice how if we didn't have this say let's suppose we did not, we did not have um because this

155
00:08:34,160 --> 00:08:35,000
is three by three.

156
00:08:35,000 --> 00:08:37,730
So let's suppose we do not have this last row.

157
00:08:37,730 --> 00:08:40,790
So we, we only had this output which was that is two by three.

158
00:08:40,790 --> 00:08:42,020
And here we had two by three.

159
00:08:42,020 --> 00:08:48,890
Then it means that when we take one by three plus five by zero, then what we want to have this one

160
00:08:48,890 --> 00:08:51,680
by its corresponding here it wouldn't match.

161
00:08:51,680 --> 00:08:57,350
And so this makes sense that the number of rows here, the number of rows should match with the number

162
00:08:57,350 --> 00:08:58,280
of columns here.

163
00:08:58,280 --> 00:09:01,430
Because that's exactly how matrix multiplication is computed.

164
00:09:01,700 --> 00:09:09,560
Now getting back, we could obviously calculate the matrix multiplication by simply doing a at um b.

165
00:09:09,560 --> 00:09:13,400
So if you do a at B you see you still have the exact same output.

166
00:09:13,520 --> 00:09:15,980
Our next operation will be the transpose.

167
00:09:15,980 --> 00:09:21,830
So let's suppose we have again a let's let's let's get let's copy this a we add from here.

168
00:09:21,830 --> 00:09:29,270
Let's just copy this B if we take this well what will be the transpose will not be very clear with the

169
00:09:29,270 --> 00:09:32,390
A is much clearer since it's not a square matrix.

170
00:09:32,390 --> 00:09:34,970
So let's let's print that out.

171
00:09:35,480 --> 00:09:38,930
Um, we have A151730.

172
00:09:38,960 --> 00:09:39,920
Let's get back to the board.

173
00:09:39,920 --> 00:09:42,650
151 um, 730.

174
00:09:42,860 --> 00:09:44,120
Let's copy this.

175
00:09:45,440 --> 00:09:46,490
There we go.

176
00:09:46,520 --> 00:09:50,990
We simply copy that, paste it out, and then there we go.

177
00:09:50,990 --> 00:09:52,430
Let's take the scroll down.

178
00:09:52,430 --> 00:09:53,150
So that's it.

179
00:09:53,150 --> 00:09:55,340
So now we have this matrix right here.

180
00:09:55,460 --> 00:09:56,630
Let's take this off.

181
00:09:56,630 --> 00:09:57,950
We have this matrix.

182
00:09:57,950 --> 00:10:00,800
And what the transpose does is simple.

183
00:10:00,800 --> 00:10:09,920
So here if we have um a matrix like this one, if we have a matrix like this one where we have 151730,

184
00:10:09,920 --> 00:10:17,120
then to obtain the transpose, all we need to do is make sure that all the rows.

185
00:10:18,020 --> 00:10:20,630
Now become Collants.

186
00:10:21,230 --> 00:10:25,760
So all the rows become columns, and all the columns obviously will become rows.

187
00:10:25,760 --> 00:10:30,500
So this row here will become or the second row becomes our second column.

188
00:10:30,500 --> 00:10:35,720
So we have we have this next one right here.

189
00:10:35,720 --> 00:10:39,560
So now we'll have 151.

190
00:10:39,560 --> 00:10:43,460
So we go from 151 as rows now to 151 as column.

191
00:10:43,460 --> 00:10:44,900
Then 730.

192
00:10:44,900 --> 00:10:48,530
We have 730 as column.

193
00:10:48,530 --> 00:10:54,620
Notice how the the columns this 171 have now become the rows.

194
00:10:54,620 --> 00:10:57,230
So 171 is now a row.

195
00:10:57,230 --> 00:11:01,310
Um five three which was a column is now a row, one zero is now a row.

196
00:11:01,310 --> 00:11:05,150
So this is what we call the transpose operation.

197
00:11:05,150 --> 00:11:10,580
And using TensorFlow again it's quite easy to make use of this um operation.

198
00:11:10,580 --> 00:11:12,080
So let's get back here.

199
00:11:12,080 --> 00:11:16,910
And let's say we do um let's print out spring.

200
00:11:16,910 --> 00:11:20,180
Let's print out um transpose.

201
00:11:20,630 --> 00:11:23,540
Um a so let's run that and see what we get.

202
00:11:23,840 --> 00:11:27,140
So we have A151 um, 730.

203
00:11:27,140 --> 00:11:31,910
Now we have 1753 and one zero exactly as we expect.

204
00:11:32,270 --> 00:11:33,890
Um, that's it for the transpose.

205
00:11:33,890 --> 00:11:35,690
It's a simple operation.

206
00:11:35,690 --> 00:11:39,170
We could take this off and see how we could change this.

207
00:11:39,170 --> 00:11:45,680
So we're going from an output or an input, which is that's a we go from an input which is one by three

208
00:11:45,680 --> 00:11:47,180
to an output which is three by one.

209
00:11:47,180 --> 00:11:53,090
Also what happens with the transpose is the number of rows, um, changes to become number of columns

210
00:11:53,090 --> 00:11:55,040
and number of columns changes to become number of rows.

211
00:11:55,040 --> 00:11:58,160
So we go from 1 to 3 now to three one.

212
00:11:58,160 --> 00:12:03,950
Also note that when you're carrying out this, um, matrix multiplication, if you get back to the documentation,

213
00:12:03,950 --> 00:12:07,940
you might have noticed that we had this transpose A, transpose B.

214
00:12:07,940 --> 00:12:16,610
So let's get again, get back here to the code, um, and say we want to um, compute this matrix multiplication.

215
00:12:16,610 --> 00:12:20,180
So let's say we want to have um let's print that out.

216
00:12:20,570 --> 00:12:23,600
Um, Linalg Matmul.

217
00:12:23,600 --> 00:12:30,050
And then we have a and B and let's, let's suppose that we wanted to, to multiply A with the transpose

218
00:12:30,050 --> 00:12:30,590
of B.

219
00:12:30,590 --> 00:12:34,520
Well, in this case, um, our A is one three.

220
00:12:34,520 --> 00:12:39,590
And so if we're, if we were to have that's B okay B is three three.

221
00:12:39,590 --> 00:12:41,390
So that that should be fine.

222
00:12:41,390 --> 00:12:48,860
So let's say we have a um at B13 by three three should give us an output which is one three.

223
00:12:48,860 --> 00:12:51,080
So that's that makes sense now.

224
00:12:51,080 --> 00:12:54,710
So A is 13B is three three.

225
00:12:54,830 --> 00:12:59,630
And we have that output which is um three or rather one three.

226
00:12:59,630 --> 00:13:05,690
Now if we compute the transpose of this three three matrix it's still going to be three three because

227
00:13:05,690 --> 00:13:07,100
the it's going to be the same.

228
00:13:07,100 --> 00:13:09,410
Um, because number of rows equal number of columns.

229
00:13:09,410 --> 00:13:11,000
So it's not going to change anything.

230
00:13:11,180 --> 00:13:17,480
So let's suppose we want to multiply a, let's get the the matrix multiplication of a and b transpose.

231
00:13:17,480 --> 00:13:20,840
In that case we would have a at TensorFlow.

232
00:13:20,840 --> 00:13:23,810
Um transpose and then b.

233
00:13:23,810 --> 00:13:28,070
So we run that and see we get 17 1227.

234
00:13:28,070 --> 00:13:32,510
Now if we were to do it in another way we could do TensorFlow Linalg.

235
00:13:33,170 --> 00:13:34,490
Uh linalg.

236
00:13:34,760 --> 00:13:36,710
Uh, matrix multiplication.

237
00:13:37,880 --> 00:13:43,670
Um, and then here we specify a, we specify b, and then just as in the documentation where we had

238
00:13:43,670 --> 00:13:48,950
transpose B um set to to false initially we could now set that to true.

239
00:13:48,950 --> 00:13:52,190
So we have transpose B set to true.

240
00:13:52,190 --> 00:13:57,290
So essentially what we're saying here is we multiply a and b with the difference that b is the is is

241
00:13:57,290 --> 00:13:58,040
transpose instead.

242
00:13:58,040 --> 00:14:00,620
So we're getting a times B transpose.

243
00:14:00,620 --> 00:14:01,850
So we run that.

244
00:14:01,850 --> 00:14:04,160
And you see we have the exact same output.

245
00:14:04,160 --> 00:14:08,630
So this shows you two different ways of carrying out this um exact same computation.

246
00:14:08,630 --> 00:14:17,030
Again um transpose and B um, didn't stop or didn't bring an error because the number of rows equal

247
00:14:17,030 --> 00:14:17,840
the number of columns.

248
00:14:17,840 --> 00:14:21,710
So if we had b, let's say we we had changed B.

249
00:14:22,310 --> 00:14:23,180
Let's take this off.

250
00:14:23,180 --> 00:14:26,960
So now let's say b is three by two on that.

251
00:14:26,960 --> 00:14:36,110
And then we get back here we should get an error because um two by three or rather this a a which is

252
00:14:36,110 --> 00:14:38,240
one by three doesn't match.

253
00:14:38,300 --> 00:14:39,740
Um two by three.

254
00:14:40,160 --> 00:14:41,870
Let's make that much clearer.

255
00:14:41,870 --> 00:14:44,930
Let's run A and B side by side and print out the shape.

256
00:14:44,930 --> 00:14:48,020
You see here that this computation could actually work.

257
00:14:48,020 --> 00:14:55,430
But when you do the transpose, when you do the transpose of B, that's when you do, um, the transpose

258
00:14:55,790 --> 00:14:59,270
transpose of B, and then you get a shape.

259
00:15:00,560 --> 00:15:01,400
You get a shape.

260
00:15:01,400 --> 00:15:04,280
You find that one three cannot match with two three.

261
00:15:04,280 --> 00:15:07,970
Because number of columns here is different from number of rows we have here.

262
00:15:07,970 --> 00:15:09,260
That's why we're getting this error.

263
00:15:09,260 --> 00:15:11,450
And so if we just had b.

264
00:15:12,470 --> 00:15:15,050
Obviously we should have no error.

265
00:15:15,260 --> 00:15:19,340
So far we have been using the TensorFlow transpose method.

266
00:15:19,370 --> 00:15:21,800
We could simply change this by doing.

267
00:15:21,800 --> 00:15:28,250
If you want to use a linear method, or here we have matrix uh matrix transpose.

268
00:15:28,250 --> 00:15:28,880
That's fine.

269
00:15:28,880 --> 00:15:30,110
So let's run that again.

270
00:15:30,110 --> 00:15:32,870
And normally everything should work.

271
00:15:32,870 --> 00:15:40,820
Um, as expected from this point we'll look at how to carry out matrix multiplication for um tensors

272
00:15:40,820 --> 00:15:42,620
which are greater than 2D.

273
00:15:42,620 --> 00:15:45,650
So let's suppose we have a 3D tensor.

274
00:15:46,100 --> 00:15:50,450
Um let's take some example of a 3D tensor which we had done previously.

275
00:15:50,450 --> 00:15:51,710
Let's get back up.

276
00:15:52,070 --> 00:15:55,370
We have this 3D tensor right here.

277
00:15:55,370 --> 00:15:56,780
Let's get back from here.

278
00:15:57,350 --> 00:16:01,280
We paste that out um just below.

279
00:16:01,280 --> 00:16:02,120
So let's paste it out.

280
00:16:02,120 --> 00:16:04,280
Here we have this tensor.

281
00:16:04,820 --> 00:16:06,260
Well let us call this a.

282
00:16:06,260 --> 00:16:13,130
So let's suppose we have this tensor A right here we have this tensor a.

283
00:16:13,130 --> 00:16:14,330
There we go.

284
00:16:14,330 --> 00:16:15,800
We have our tensor A.

285
00:16:15,800 --> 00:16:20,510
And then we want to multiply this tensor A by uh another tensor b.

286
00:16:20,510 --> 00:16:26,450
So let's say let's take let's copy this again and paste out here we have tensor A.

287
00:16:26,480 --> 00:16:30,200
We have tensor B which for now are exactly the same tensors.

288
00:16:30,590 --> 00:16:31,550
That's fine.

289
00:16:31,730 --> 00:16:36,320
We'll just run this and then print out a shape.

290
00:16:36,890 --> 00:16:38,450
We'll print out B shape.

291
00:16:38,450 --> 00:16:41,450
And then we try to uh multiply this two.

292
00:16:41,450 --> 00:16:48,710
So well let's just print out the shapes first and then we do a or TensorFlow linalg.

293
00:16:49,070 --> 00:16:52,580
Um matmul a comma b.

294
00:16:53,390 --> 00:16:55,790
So you see again we have this error.

295
00:16:55,790 --> 00:17:02,720
But the reason why we're having this error is because when you're doing matrix multiplication over batches

296
00:17:02,720 --> 00:17:09,320
of, um data, we consider each and every batch and try to carry out the matrix multiplication for that

297
00:17:09,320 --> 00:17:09,800
batch.

298
00:17:09,800 --> 00:17:14,990
But then for each and every batch we have here, if you look at this, let's reduce this so you can

299
00:17:14,990 --> 00:17:16,610
see the two at once.

300
00:17:16,610 --> 00:17:21,500
If you look at this right here, you'll notice that this is two by three.

301
00:17:21,500 --> 00:17:23,330
So this is here two by three.

302
00:17:24,250 --> 00:17:28,630
Here we have two by three and then here we also have two by three.

303
00:17:28,630 --> 00:17:33,700
And obviously because the number of columns in this case, which is three, doesn't match the number

304
00:17:33,700 --> 00:17:36,610
of rows, in this case which is two, we get that error.

305
00:17:36,610 --> 00:17:44,650
So if we convert this into because here we have um looking at the shape we have for x, here we have

306
00:17:44,650 --> 00:17:47,290
for two by three matrices.

307
00:17:47,290 --> 00:17:49,480
Here we have for two by three matrices.

308
00:17:49,480 --> 00:17:50,980
So two by three.

309
00:17:50,980 --> 00:17:54,610
If we change this um from two by 3 to 2 by two.

310
00:17:54,610 --> 00:17:57,760
So let's make sure that each and every one of this now is two by two.

311
00:17:57,760 --> 00:17:58,750
Let's get back.

312
00:17:58,750 --> 00:18:02,830
We have two by two, two by two.

313
00:18:03,700 --> 00:18:04,660
There we go.

314
00:18:04,660 --> 00:18:05,800
Two by two.

315
00:18:06,490 --> 00:18:11,140
And then finally we have two by two for this last, um, element.

316
00:18:11,140 --> 00:18:12,490
So we run that again.

317
00:18:12,490 --> 00:18:16,270
We get a shape do matrix multiplication and we have an output.

318
00:18:16,270 --> 00:18:19,450
So because this is two by two this two matches with this two.

319
00:18:19,450 --> 00:18:20,260
And that's fine.

320
00:18:20,260 --> 00:18:28,090
So again as we're seeing the matrix multiplication where we have uh a 3D tensor like this one is carried

321
00:18:28,090 --> 00:18:38,800
out in such a way that each and every um, block of 2D, there is some sort of block wise matrix multiplication.

322
00:18:38,800 --> 00:18:43,870
So this block is multiplied with this block, this block multiplied with this block.

323
00:18:44,170 --> 00:18:49,570
Um, then this block, multiply with this block, then this last block.

324
00:18:49,570 --> 00:18:51,010
Multiply with this last block.

325
00:18:51,010 --> 00:18:55,690
Now to test this out, you could simply say, what if we do a zero.

326
00:18:55,690 --> 00:18:56,980
So let's get a zero.

327
00:18:56,980 --> 00:19:00,280
If we do a zero uh let's print out a zero.

328
00:19:00,940 --> 00:19:04,480
And then um we print out B zero.

329
00:19:04,480 --> 00:19:07,660
So we get the first block or the first two blocks.

330
00:19:07,660 --> 00:19:09,310
Here we have one, two, three, four, five.

331
00:19:09,310 --> 00:19:11,170
And here we have 12035.

332
00:19:11,170 --> 00:19:15,130
Negative one 1235312035.

333
00:19:15,130 --> 00:19:15,670
Negative one.

334
00:19:15,670 --> 00:19:16,690
Which is what we expect.

335
00:19:16,690 --> 00:19:23,530
Now let's do a zero um times a zero times B zero.

336
00:19:23,530 --> 00:19:24,370
We run that.

337
00:19:25,660 --> 00:19:29,800
You expect the output to be exactly what we had for the first block here.

338
00:19:29,800 --> 00:19:35,350
So we have 712 -218, 31 negative five, which is exactly what we expect here.

339
00:19:35,380 --> 00:19:39,970
Now if we change this to let's say two two run that again.

340
00:19:39,970 --> 00:19:42,970
We expect to have this exact output.

341
00:19:42,970 --> 00:19:43,600
See that.

342
00:19:43,600 --> 00:19:51,850
So this tells us that uh, when we multiplying um, two 3D um, tensors, we are simply carrying out

343
00:19:51,850 --> 00:19:55,180
a block wise, uh, matrix multiplication.

344
00:19:55,810 --> 00:19:58,780
For our next method we check out the barn part method.

345
00:19:58,780 --> 00:20:00,820
Let's get to barn part.

346
00:20:00,820 --> 00:20:03,670
So here we have barn part.

347
00:20:04,640 --> 00:20:05,960
Scroll to the top.

348
00:20:05,960 --> 00:20:14,060
What it does is it copies a tensor, setting everything outside the central band in each innermost matrix

349
00:20:14,060 --> 00:20:14,960
to zero.

350
00:20:14,990 --> 00:20:22,370
Now, um, you have this this explanation and maybe this, um, definition here, which looks a bit

351
00:20:22,370 --> 00:20:23,030
complicated.

352
00:20:23,030 --> 00:20:25,430
And, and so we're going to break this up.

353
00:20:25,430 --> 00:20:28,730
So here we have also this you see this definition.

354
00:20:29,210 --> 00:20:35,720
Uh, we told that the band of this matrix, um, is in band m n times the input matrix.

355
00:20:35,720 --> 00:20:39,980
And then the in band is defined or the indicator function is defined as such.

356
00:20:39,980 --> 00:20:48,290
So this function essentially what it does is it's um capable of maintaining all the values of a given

357
00:20:48,290 --> 00:20:55,520
input while turning some of the values all to zeros, just as it was, um, defined here.

358
00:20:55,520 --> 00:21:02,420
So let's go ahead and copy our this input, this simple example and then um, see how we could obtain

359
00:21:02,420 --> 00:21:03,290
the output.

360
00:21:03,290 --> 00:21:05,690
So let's get back here.

361
00:21:05,960 --> 00:21:08,450
Uh, we could just take we could just take what we had already from here.

362
00:21:08,450 --> 00:21:11,150
So let's just, let's just copy an example.

363
00:21:11,150 --> 00:21:15,500
We had, um, let's take a three by three matrix.

364
00:21:15,920 --> 00:21:20,300
Well, let's just copy this and then we'll just turn this into a three by three matrix.

365
00:21:20,300 --> 00:21:24,680
So getting back here we have spaces out.

366
00:21:25,340 --> 00:21:28,820
Then we copy this out and paste out.

367
00:21:28,820 --> 00:21:29,870
That's fine.

368
00:21:30,620 --> 00:21:32,060
Zero.

369
00:21:32,060 --> 00:21:34,490
Um well let's not let's not set this to zero.

370
00:21:34,490 --> 00:21:37,880
Let's put one and then let's say three okay.

371
00:21:37,880 --> 00:21:40,550
So five or let's say nine okay.

372
00:21:40,550 --> 00:21:41,150
So that's it.

373
00:21:41,150 --> 00:21:43,130
So this is our input matrix A.

374
00:21:43,130 --> 00:21:53,060
And what we want to get is um linear band part of A while specifying the the lower number to be zero

375
00:21:53,060 --> 00:21:55,850
and the upper number to be zero.

376
00:21:56,030 --> 00:22:01,250
So we will come and copy the definition and see how we could produce or generate the output.

377
00:22:01,250 --> 00:22:06,560
We'll go step by step and see how this output here is generated.

378
00:22:06,560 --> 00:22:09,320
So we have this condition right here.

379
00:22:09,320 --> 00:22:12,920
Let's let's take this off so we could see only the conditions.

380
00:22:13,250 --> 00:22:14,720
See we have this conditions.

381
00:22:14,720 --> 00:22:21,920
And now because our num lower is zero here this condition is never going to be verified.

382
00:22:21,920 --> 00:22:23,180
So this is false.

383
00:22:23,180 --> 00:22:27,170
And then if we continue here our num upper is zero.

384
00:22:27,170 --> 00:22:29,060
So this condition is never going to be verified.

385
00:22:29,060 --> 00:22:29,420
Two.

386
00:22:29,420 --> 00:22:32,840
So here already we have this condition which is never going to be verified.

387
00:22:32,840 --> 00:22:35,300
And this condition which is never going to be verified.

388
00:22:35,300 --> 00:22:41,750
Now for the next for the other conditions, for this other conditions, it will depend on the position

389
00:22:41,750 --> 00:22:43,070
of that element.

390
00:22:43,070 --> 00:22:46,850
So if we take this position here we have m.

391
00:22:46,850 --> 00:22:50,390
So if we take this position here we have m.

392
00:22:50,390 --> 00:22:52,340
Let's um put this down.

393
00:22:52,340 --> 00:23:00,590
Here we have m equals zero and then n equals zero because this is the zeroth row and the zeroth column.

394
00:23:00,590 --> 00:23:10,520
So because m equals zero and n equals zero um m minus n we have m minus n uh which is equal um zero.

395
00:23:10,520 --> 00:23:13,610
We have n minus m which is equal to zero.

396
00:23:13,610 --> 00:23:16,340
And then m minus n which is zero.

397
00:23:16,340 --> 00:23:19,970
So we have is zero less than or equal zero.

398
00:23:20,000 --> 00:23:21,050
Yes that's true.

399
00:23:21,050 --> 00:23:25,610
So now we will have here true here we have true.

400
00:23:25,610 --> 00:23:26,570
That's true.

401
00:23:27,650 --> 00:23:31,760
Is zero less than or equal to um zero.

402
00:23:31,790 --> 00:23:32,840
That's true.

403
00:23:32,840 --> 00:23:35,840
So it means that uh because this is an R.

404
00:23:35,870 --> 00:23:40,820
Remember with the r, um, any of them need to be true for us to have true.

405
00:23:40,820 --> 00:23:45,260
So the r is only false when we have this condition false and this condition false.

406
00:23:45,260 --> 00:23:50,390
So because one of this is true, our final output here is true.

407
00:23:50,390 --> 00:23:52,700
So let's pick this up again.

408
00:23:52,700 --> 00:23:55,460
We have um at the center.

409
00:23:55,460 --> 00:23:57,530
Now we have true.

410
00:23:57,710 --> 00:24:02,960
And then um on this other side because one is true, we also have true.

411
00:24:03,680 --> 00:24:05,090
You see we have true.

412
00:24:05,540 --> 00:24:11,840
Now for our overall condition to be true because we have the end, because here we have true here to

413
00:24:11,840 --> 00:24:14,360
the left we have true, and to the right we have true.

414
00:24:14,720 --> 00:24:16,040
Um, these two must be true.

415
00:24:16,040 --> 00:24:16,820
And that's the case.

416
00:24:16,820 --> 00:24:19,130
So overall we have true.

417
00:24:19,130 --> 00:24:21,950
So finally we have true.

418
00:24:22,490 --> 00:24:27,770
And because we have true this value of one, if, you know, if you look here is maintained.

419
00:24:28,770 --> 00:24:31,200
If it were false, then the value would not be maintained.

420
00:24:31,230 --> 00:24:33,240
Now let's take a different example.

421
00:24:33,240 --> 00:24:37,110
Let's say when m is equal zero and n equal one.

422
00:24:37,110 --> 00:24:43,650
If m equals zero and n equal one, that's where this zeroth row and we are at column one.

423
00:24:43,650 --> 00:24:52,140
So we fall in this value five um m minus n is um negative one and n minus m is one.

424
00:24:52,140 --> 00:24:52,890
So that's it.

425
00:24:53,490 --> 00:24:54,630
Let's take this here.

426
00:24:55,170 --> 00:24:58,470
Um n minus n negative one n minus m one.

427
00:24:58,470 --> 00:25:03,840
Now the again we have this false because our num lower is zero.

428
00:25:03,840 --> 00:25:05,760
So we have false we have false.

429
00:25:05,760 --> 00:25:10,740
And then for m minus n m minus n is negative one is less than zero.

430
00:25:10,740 --> 00:25:11,610
So this is true.

431
00:25:11,610 --> 00:25:12,600
So that's fine.

432
00:25:12,750 --> 00:25:15,540
Here we have n minus m which is one.

433
00:25:15,540 --> 00:25:18,870
It is um not less than um zero.

434
00:25:18,870 --> 00:25:19,980
It's not less than or equal to zero.

435
00:25:19,980 --> 00:25:21,600
So this tends to be false.

436
00:25:21,600 --> 00:25:23,310
So here we have false.

437
00:25:23,910 --> 00:25:26,580
And so this is false true.

438
00:25:26,580 --> 00:25:29,130
This is ah so this this is true.

439
00:25:29,130 --> 00:25:32,100
And here we have false false.

440
00:25:32,820 --> 00:25:35,010
And it's ah so it's false.

441
00:25:35,070 --> 00:25:38,160
See now here we have true false because we have.

442
00:25:38,160 --> 00:25:40,680
And the two must be true false to have true.

443
00:25:40,680 --> 00:25:42,660
So we end up with a false.

444
00:25:43,050 --> 00:25:47,010
And because we end up with a false the five is changed to zero.

445
00:25:47,010 --> 00:25:50,790
So that's how we, we we we get this um, position here.

446
00:25:50,880 --> 00:25:58,200
Now you'll note that for the rest we will have something similar where generally, um, it's only when

447
00:25:58,200 --> 00:26:05,160
m is equal, n is only going to be where m is equal to n that we are going to have um true in the output.

448
00:26:05,160 --> 00:26:12,060
And so we have an output where all the values which are not on the diagonal are always zeros.

449
00:26:12,060 --> 00:26:14,940
So that's the this um, band part method.

450
00:26:14,940 --> 00:26:21,270
When we set num lower to zero and num upper to zero, if we get back here you'll see that we have some

451
00:26:21,270 --> 00:26:22,230
special cases.

452
00:26:22,230 --> 00:26:24,780
So these are some useful special cases.

453
00:26:25,050 --> 00:26:26,280
Let's take back this.

454
00:26:27,230 --> 00:26:28,250
You see that running this?

455
00:26:28,250 --> 00:26:29,720
Now we have for this.

456
00:26:29,720 --> 00:26:34,670
First the upper we have the upper triangular part which is nonzero.

457
00:26:34,670 --> 00:26:41,390
So um, first of all, if you look at a this is a the upper triangular part remains intact, whereas

458
00:26:41,390 --> 00:26:44,090
the lower triangular part is all turned to zeros.

459
00:26:44,090 --> 00:26:54,680
Now essentially what this means is if you have an input like this one, let's say we have um 356, um,

460
00:26:54,680 --> 00:27:01,700
102 um 113.

461
00:27:02,450 --> 00:27:04,490
And then here we have two.

462
00:27:04,520 --> 00:27:05,540
This is one.

463
00:27:06,090 --> 00:27:09,450
When we say we want to have the upper triangular part.

464
00:27:09,450 --> 00:27:13,470
Let's reduce this when we say we have the upper triangular part.

465
00:27:13,530 --> 00:27:20,850
Um, that is all this um parts here uh be non zeros, whereas all the, the lower triangular part is

466
00:27:20,850 --> 00:27:21,780
set to zero.

467
00:27:21,780 --> 00:27:28,170
Then what that simply means is, um, you break up your matrix into two parts, so we into two triangles.

468
00:27:28,170 --> 00:27:30,480
So you have this triangle.

469
00:27:32,260 --> 00:27:36,040
And you also have this, um, triangle.

470
00:27:36,040 --> 00:27:40,990
Well, let's get back because this is this is the upper triangle, actually.

471
00:27:40,990 --> 00:27:43,990
So this is the upper triangular part.

472
00:27:43,990 --> 00:27:46,330
This is a lower triangular part.

473
00:27:46,330 --> 00:27:48,190
So we have this two triangles.

474
00:27:48,190 --> 00:27:50,410
And then we have this diagonal.

475
00:27:50,410 --> 00:27:55,210
So as we have seen already uh, when we set when we have zero zero.

476
00:27:55,820 --> 00:27:59,600
The lower triangle and this upper triangle is zero.

477
00:27:59,600 --> 00:28:06,020
Whereas when we have, um, let's take this other condition, when we have negative one zero, we have

478
00:28:06,020 --> 00:28:12,740
your the lower triangle which is set to zero, whereas this remains intact and the diagonal also remains

479
00:28:12,740 --> 00:28:13,370
intact.

480
00:28:13,370 --> 00:28:18,050
And then uh, when we have um, zero negative one.

481
00:28:18,050 --> 00:28:20,540
Well this would be this is zero negative one.

482
00:28:20,540 --> 00:28:25,940
When we have negative one zero we instead have the upper part which is set to zero as you could see

483
00:28:25,940 --> 00:28:26,360
here.

484
00:28:26,360 --> 00:28:31,940
So when we have zero negative one or rather negative one zero when we have negative one uh negative

485
00:28:31,940 --> 00:28:34,910
one zero is this upper part which is set to zero.

486
00:28:34,910 --> 00:28:36,380
Now there are some special cases.

487
00:28:36,380 --> 00:28:42,950
Or in practice you may want to have an output which is having um, let's say this upper part, this

488
00:28:42,950 --> 00:28:46,520
upper triangular part set to zero or maybe the lower triangular part set to zero.

489
00:28:46,520 --> 00:28:50,300
And in that case, uh, the band part method comes very handy.

490
00:28:50,780 --> 00:28:57,920
Another method which we have is the determinant, um, which helps us compute the determinant of a square

491
00:28:57,920 --> 00:28:58,400
matrix.

492
00:28:58,400 --> 00:29:00,890
So it's important to know that this is a square matrix.

493
00:29:00,890 --> 00:29:02,570
That is M should be equal to n.

494
00:29:02,570 --> 00:29:05,210
So the number of rows should be equal number of columns.

495
00:29:05,660 --> 00:29:11,810
Um that's um a very simple method which is which you could use depending on what problem you're trying

496
00:29:11,810 --> 00:29:12,530
to solve.

497
00:29:12,530 --> 00:29:14,660
Then we also have the inverse.

498
00:29:14,660 --> 00:29:17,090
So let's go to I, we have the inverse.

499
00:29:17,660 --> 00:29:18,920
There we go.

500
00:29:18,920 --> 00:29:26,180
Now note that the inverse of a matrix is one which is defined, um, such that the inverse of a matrix

501
00:29:26,180 --> 00:29:31,010
is one which is um defined such that a inverse.

502
00:29:32,740 --> 00:29:33,820
Times a.

503
00:29:34,710 --> 00:29:40,230
So the inverse of a is such that a inverse times A gives you the identity matrix.

504
00:29:40,230 --> 00:29:52,800
So if A if we have A to be a two by two matrix, which is like um, say um x um x x x whatever value

505
00:29:52,830 --> 00:30:00,990
we have in here, multiplying this with this inverse will give you the identity matrix which is one,

506
00:30:00,990 --> 00:30:05,190
zero, um, zero and one.

507
00:30:05,190 --> 00:30:11,070
And so if you have a matrix like this one and you want to find a matrix such that when you multiply

508
00:30:11,070 --> 00:30:17,520
with this, um, matrix, it gives you the identity matrix, then you could make use of this TensorFlow

509
00:30:17,550 --> 00:30:18,810
um inverse method.

510
00:30:18,810 --> 00:30:20,130
So that's it.

511
00:30:20,130 --> 00:30:25,260
So you could compute the inverse of one or more square invertible matrices or the adjoints.

512
00:30:25,260 --> 00:30:26,550
So that's it.

513
00:30:27,240 --> 00:30:30,600
The next method we'll be looking at is the Insum.

514
00:30:30,600 --> 00:30:38,970
The Insum operator offers a clever way of carrying out matrix computations by taking into consideration

515
00:30:38,970 --> 00:30:43,890
just the shapes of the different matrices of the different tensors.

516
00:30:44,310 --> 00:30:49,620
To better understand how the Insum operator works, we shall take several examples.

517
00:30:49,620 --> 00:30:52,320
So let's start with the matrix multiplication.

518
00:30:52,320 --> 00:30:58,890
Right here we have a b and then we carry out matrix multiplication of of a and b.

519
00:30:58,890 --> 00:31:00,180
And then we obtain c.

520
00:31:00,510 --> 00:31:05,850
Obviously, because the number of columns of a equal number of rows of b, this matrix multiplication

521
00:31:05,850 --> 00:31:06,420
is valid.

522
00:31:06,420 --> 00:31:09,570
And we have this output which is of shape three by five.

523
00:31:09,570 --> 00:31:11,520
So here is the output we get.

524
00:31:11,520 --> 00:31:19,560
Now if we were to use the insum operator to get the value of c, what would make use of will be the

525
00:31:19,560 --> 00:31:22,800
shapes of our um different matrices.

526
00:31:22,800 --> 00:31:32,490
So this for example is three by four and then b is um four by five.

527
00:31:32,850 --> 00:31:35,670
Obviously the output c is three by five.

528
00:31:35,910 --> 00:31:39,600
And so if here we have I g.

529
00:31:39,600 --> 00:31:43,290
So we take this to b I g we put a comma.

530
00:31:43,290 --> 00:31:46,980
And then here we have g k.

531
00:31:47,940 --> 00:31:53,340
Then our output is going to be I k.

532
00:31:53,370 --> 00:31:55,770
Notice how this j is the same as this g.

533
00:31:55,770 --> 00:31:58,380
So because we we these two must be the same.

534
00:31:58,380 --> 00:31:59,820
We maintain the j.

535
00:31:59,820 --> 00:32:03,570
But we have your I and then k as output.

536
00:32:03,570 --> 00:32:06,810
So here we have I um k.

537
00:32:07,350 --> 00:32:12,960
And so if we want to translate that into code we will have um TensorFlow I insum.

538
00:32:13,170 --> 00:32:18,210
And then we will have the string which takes I j comma j k.

539
00:32:18,210 --> 00:32:22,110
So we want to multiply a which which has a shape.

540
00:32:22,110 --> 00:32:23,700
And then by b.

541
00:32:23,700 --> 00:32:28,950
And then the output is going to be I k which is now c.

542
00:32:28,950 --> 00:32:34,800
So we pass in a and b and it understands that this is a and this is for b.

543
00:32:34,800 --> 00:32:38,280
So let's run this and then get this output I k.

544
00:32:38,280 --> 00:32:43,710
So you see here we have the exact same output as um with the matrix multiplication.

545
00:32:43,710 --> 00:32:46,770
Now another example we could take is the dot product.

546
00:32:46,770 --> 00:32:50,790
So let's suppose that we have um two vectors.

547
00:32:50,790 --> 00:32:55,020
So let's let's um set a and b again let's just copy this.

548
00:32:55,020 --> 00:33:01,020
So we have two vectors a um just one d.

549
00:33:01,140 --> 00:33:04,200
So here we have or we take this off.

550
00:33:04,200 --> 00:33:05,940
Well let's just take all this off.

551
00:33:06,270 --> 00:33:08,340
Take this, put this here.

552
00:33:08,340 --> 00:33:12,090
And then uh, we create our 1D tensor.

553
00:33:12,090 --> 00:33:14,700
So we have this 1D tensor which is our vector.

554
00:33:14,700 --> 00:33:17,610
And then we want to do a dot b.

555
00:33:17,610 --> 00:33:20,670
So dot product we want to get the dot product of a and b.

556
00:33:21,330 --> 00:33:24,060
Um here we have say zero.

557
00:33:24,060 --> 00:33:26,520
Let's say one let's say three.

558
00:33:26,520 --> 00:33:28,470
And then let's say nine okay.

559
00:33:28,470 --> 00:33:30,660
So well let's just put this a small number.

560
00:33:30,660 --> 00:33:36,480
So if we were to calculate this manually we would have two times zero plus which is zero.

561
00:33:36,480 --> 00:33:43,800
So we'd have zero plus um six times one which is six plus five times three which is 15 plus two times

562
00:33:43,800 --> 00:33:44,730
two which is four.

563
00:33:44,730 --> 00:33:47,550
So in that case we are going to be having 21 plus four.

564
00:33:47,580 --> 00:33:49,230
That's 25 okay.

565
00:33:49,230 --> 00:33:56,010
So if we want to um compute the dot product, what we'll do here is we would make use of the Insum.

566
00:33:56,010 --> 00:33:57,570
So we have Insum.

567
00:33:57,570 --> 00:34:04,350
And then because we have a here which has a shape I because it's not it's not 2D it's 1D.

568
00:34:04,350 --> 00:34:09,870
So we just have I and then we have B which is um shape j c.

569
00:34:09,870 --> 00:34:14,970
So um like before here we had this comma separating the two.

570
00:34:14,970 --> 00:34:16,350
So let's put that comma.

571
00:34:16,380 --> 00:34:19,140
You see this is a this is B.

572
00:34:19,140 --> 00:34:25,110
And then the output is going to have no shape because it's going to have uh it's going to be a scalar.

573
00:34:25,110 --> 00:34:29,100
So because it's going to be a scalar we put nothing um in front of the arrow.

574
00:34:29,100 --> 00:34:33,330
And then we just simply put in A and B we run that and there we go.

575
00:34:33,330 --> 00:34:34,290
We have 90.

576
00:34:35,000 --> 00:34:38,480
We are expecting to get 25, but we instead got 90.

577
00:34:38,570 --> 00:34:49,010
Now we have a a year, uh, which has shape four and then we have B which has shape um four.

578
00:34:49,370 --> 00:34:58,130
And then when we define this we act as if A and B, um although 1D have different shapes.

579
00:34:58,130 --> 00:35:03,950
So we, we act as if we could have six here or we could have nine or we could have whatever number,

580
00:35:04,190 --> 00:35:10,640
uh, and which is not the case because, um, for us to carry out the dot product, this tool that's

581
00:35:10,640 --> 00:35:15,230
A and B must have exactly the same shape.

582
00:35:15,230 --> 00:35:20,300
So if we have um, shape four then here we should have shape of four.

583
00:35:20,300 --> 00:35:26,090
And so that's why we have to change this g into I because this two must be the same.

584
00:35:26,090 --> 00:35:32,570
This is similar to what we had with the matrix multiplication where this j and this j or essentially

585
00:35:32,570 --> 00:35:37,250
we make sure the color here is j and the row um number is g.

586
00:35:37,250 --> 00:35:42,710
So make to let the handsome operator understand that this is um.

587
00:35:42,710 --> 00:35:44,450
This condition must be verified.

588
00:35:44,450 --> 00:35:48,440
And if this condition is verified then we have matrix multiplication.

589
00:35:48,530 --> 00:35:55,460
So getting back here, you see if we have I, I and then we output nothing meaning that we just, um,

590
00:35:55,670 --> 00:36:00,800
sum up or we just multiply and then sum up all the values since we'll get a scalar.

591
00:36:01,190 --> 00:36:06,590
Um, then if you run this again you find that we have the output 25.

592
00:36:06,740 --> 00:36:10,550
Now talking about let's get back let's get back here.

593
00:36:11,000 --> 00:36:12,890
I'll take this off and piece that out.

594
00:36:12,890 --> 00:36:14,930
Let's, let's say we had J.

595
00:36:14,930 --> 00:36:16,490
So let's say we had J.

596
00:36:16,490 --> 00:36:21,410
If we had J here then we'll be instead computing the outer product.

597
00:36:21,440 --> 00:36:26,840
Now with the outer product is is is different because we could have something of different length.

598
00:36:26,840 --> 00:36:29,630
We could have one uh, and that would still work.

599
00:36:29,630 --> 00:36:34,820
So if you run that you'll still have an output because I and J could be different.

600
00:36:34,820 --> 00:36:40,400
But if you get here and you have one and you run this, you should get an error.

601
00:36:40,400 --> 00:36:42,770
You see, um, that's an error.

602
00:36:42,770 --> 00:36:45,200
Which makes sense because this is are the same.

603
00:36:45,200 --> 00:36:48,290
So let's get back, run that again and get back here.

604
00:36:48,290 --> 00:36:49,100
So that's it.

605
00:36:49,100 --> 00:36:56,480
So you see that's that's what we have now if we do if after this that's after this I, we do let's say

606
00:36:56,480 --> 00:37:03,860
we want to have an output I, we run that you see we have the output that we have here is still another

607
00:37:03,860 --> 00:37:05,420
1D tensor.

608
00:37:05,420 --> 00:37:10,760
And when you look carefully you will notice that what all what we have here is simply is simply gotten

609
00:37:10,760 --> 00:37:13,280
by multiplying each and every element here.

610
00:37:13,280 --> 00:37:16,580
So if you take this zeroth element multiply it by zero.

611
00:37:16,580 --> 00:37:17,540
That's two times zero.

612
00:37:17,540 --> 00:37:19,280
We have zero six times one.

613
00:37:19,280 --> 00:37:23,360
We have six five times three we have 15 two times two we have four.

614
00:37:23,360 --> 00:37:26,600
And then when you sum all this up we have now 25.

615
00:37:26,600 --> 00:37:31,490
So essentially when you specify that the output should be I like this.

616
00:37:31,610 --> 00:37:37,670
All what you're saying is just do the element wise multiplication and give me whatever output we get.

617
00:37:37,670 --> 00:37:45,200
But when you take this off, what you're saying is, um, generate this because after multiplying you

618
00:37:45,200 --> 00:37:46,130
will generate this.

619
00:37:46,130 --> 00:37:49,910
And then because there is no output, I want a scalar.

620
00:37:49,910 --> 00:37:53,810
And since I want the scalar, I'm going to sum all this up to produce that scalar.

621
00:37:53,810 --> 00:37:57,440
So when you run this now you see we have the 25.

622
00:37:57,530 --> 00:38:00,680
Then if we say I j we run this.

623
00:38:01,630 --> 00:38:05,530
You see, um, our script contains a level J not present the inputs.

624
00:38:05,560 --> 00:38:10,300
Well, this makes sense because obviously you cannot have, uh, you cannot introduce J when it's not

625
00:38:10,300 --> 00:38:11,170
present in the input.

626
00:38:11,170 --> 00:38:14,080
So let's have I run that again.

627
00:38:14,740 --> 00:38:19,360
Um, output subscripts contain a level appearing more than once.

628
00:38:19,660 --> 00:38:24,580
So here we told that we have this level I uh, which appeared in more than once.

629
00:38:24,580 --> 00:38:27,040
Anyway, um that's it.

630
00:38:27,040 --> 00:38:28,780
Let's take this off.

631
00:38:28,780 --> 00:38:36,130
We have our dot product, and then now we get back to our outer product for the outer product, um,

632
00:38:36,130 --> 00:38:39,430
here we have two, six, five two and then zero one, three two.

633
00:38:39,430 --> 00:38:40,960
Let's say let's take this off for now.

634
00:38:40,960 --> 00:38:48,520
So 26520132 to compute the outer product of this tool will um, rearrange this this way.

635
00:38:48,520 --> 00:38:54,100
So let's say we have this matrix or we have this tensor and then we we have this other one.

636
00:38:54,100 --> 00:38:56,500
Let's turn this like this.

637
00:38:56,500 --> 00:38:59,020
Let's get this transpose from here.

638
00:38:59,050 --> 00:39:03,250
Now we do zero times two zero times two.

639
00:39:03,250 --> 00:39:06,850
We have zero zero times six we have zero.

640
00:39:06,850 --> 00:39:08,800
Well we have all zeros here.

641
00:39:08,800 --> 00:39:11,290
And then one times two we have two.

642
00:39:11,320 --> 00:39:19,660
We just maintain this 2652 um six um 18.

643
00:39:21,200 --> 00:39:22,010
18.

644
00:39:22,010 --> 00:39:23,900
Three times five is 15.

645
00:39:25,000 --> 00:39:26,890
Three times two is six.

646
00:39:27,250 --> 00:39:29,140
Two times two is four.

647
00:39:29,230 --> 00:39:31,150
Two times six is 12.

648
00:39:31,900 --> 00:39:34,150
Um, two times five is ten.

649
00:39:34,570 --> 00:39:36,400
Two times two is four.

650
00:39:36,400 --> 00:39:38,650
So this is now our outer product.

651
00:39:38,650 --> 00:39:40,990
And this is how it's computed very easily.

652
00:39:41,230 --> 00:39:48,400
Getting back to the code, if we have this as our a and this as b, then if we say we want to have ij.

653
00:39:48,430 --> 00:39:55,030
So we want to generate this 2D matrix um which takes into consideration or which takes as input a and

654
00:39:55,030 --> 00:39:59,500
B and then our computer's outer product and we run this.

655
00:39:59,500 --> 00:40:04,090
You see we have this matrix which is similar to what we just generated with the difference that this

656
00:40:04,090 --> 00:40:05,950
is the transpose of what we got.

657
00:40:05,950 --> 00:40:12,550
Well, getting back you see this is note that this is um, let's just copy all this so we could compare

658
00:40:12,550 --> 00:40:13,900
on this on the board.

659
00:40:14,170 --> 00:40:16,240
Take this slightly up.

660
00:40:16,660 --> 00:40:21,730
As you can see, it's exactly the same, um, as the transpose of what we just computed.

661
00:40:21,730 --> 00:40:29,920
So what this tells us is when we, when we have this tool like this, the A acts as a column matrix

662
00:40:29,920 --> 00:40:33,700
and the B acts as the row matrix if we have ij.

663
00:40:33,730 --> 00:40:39,340
So this is this here, this a is a column matrix and B is a row matrix.

664
00:40:39,340 --> 00:40:43,390
So instead of 2652 where we're supposed to put it out like this.

665
00:40:43,390 --> 00:40:47,110
So it was supposed to be 2652 and then 0132.

666
00:40:47,110 --> 00:40:53,710
So that when you multiply now you have all the, um, answers, you or you have exact same response

667
00:40:53,710 --> 00:40:54,700
as expected.

668
00:40:55,270 --> 00:41:02,950
Um, if you want to have the, the original or what we had when we calculate computed this originally,

669
00:41:02,950 --> 00:41:04,150
you could instead have.

670
00:41:04,150 --> 00:41:07,180
Well this is AB, this is AB.

671
00:41:07,360 --> 00:41:09,490
And then here you could do G.

672
00:41:09,520 --> 00:41:10,750
So you run that again.

673
00:41:10,750 --> 00:41:14,170
And you see we have exactly what we got um initially.

674
00:41:14,170 --> 00:41:22,060
So this if is, if it's meant to be in order that's IJ then this is going to be our column matrix.

675
00:41:22,060 --> 00:41:24,550
And then this is going to be our row matrix.

676
00:41:24,790 --> 00:41:26,830
So let's say now that we have C.

677
00:41:26,830 --> 00:41:28,270
So this is our C.

678
00:41:28,840 --> 00:41:33,910
Um let's go ahead and compute the sum of all elements in C.

679
00:41:33,910 --> 00:41:38,140
If we want to compute this we'll simply make use of the reduce sum method.

680
00:41:38,140 --> 00:41:42,070
So reduce sum let's print that out.

681
00:41:43,360 --> 00:41:44,500
Run that again.

682
00:41:44,500 --> 00:41:46,870
And then we see that we have 90.

683
00:41:46,900 --> 00:41:47,890
Now.

684
00:41:48,100 --> 00:41:49,360
Well let's print out C.

685
00:41:49,360 --> 00:41:52,840
So we have C printed out and we have the sum of 90.

686
00:41:52,870 --> 00:42:00,310
Now what this tells us is that um initially or right here when we had computed this and then we had

687
00:42:00,310 --> 00:42:07,540
put out um, or when we had IJ, you see, remember when we had IJ um, we, we ran this and then we

688
00:42:07,540 --> 00:42:08,830
had 90.

689
00:42:08,860 --> 00:42:14,080
It was simply because we had computed the outer product instead of the dot product.

690
00:42:14,380 --> 00:42:20,380
And then we had summed up all the elements in this outer product.

691
00:42:20,380 --> 00:42:27,310
Because now if you do if you get back here, let's take this off, print it out.

692
00:42:27,310 --> 00:42:34,270
And then instead of, um, coming up with this 2D tensor, if we come up with a with a scalar by by

693
00:42:34,270 --> 00:42:40,180
saying we don't want, uh, or by simply not putting anything in the output, and you print this out,

694
00:42:40,180 --> 00:42:44,710
then you see, now that you get the exact same 90 which was expected.

695
00:42:44,710 --> 00:42:49,510
So when you sum all this and then when you just do this directly, you, you get that same 90.

696
00:42:49,510 --> 00:42:53,560
So that's why initially we had made an error um, here.

697
00:42:53,560 --> 00:42:57,910
So instead of 25 we got 90 because of that error we made.

698
00:42:57,910 --> 00:43:02,920
That's where computing the outer product instead of the dot product for the next one is going to be

699
00:43:02,920 --> 00:43:03,670
the transpose.

700
00:43:03,670 --> 00:43:11,980
So let's suppose that we have um, this matrix C um let's say we have this matrix C or well let's just,

701
00:43:11,980 --> 00:43:17,800
let's just go, go and copy out um, a again, let's try to get the, the transpose of this B we'll

702
00:43:17,800 --> 00:43:19,510
copy A or B doesn't matter.

703
00:43:19,510 --> 00:43:22,120
So let's say we get this is our b.

704
00:43:22,120 --> 00:43:23,530
So that's our b.

705
00:43:23,530 --> 00:43:29,440
And then we want to get the the transpose of B using the Insum operator.

706
00:43:29,440 --> 00:43:32,980
Then you could pause at this level and try to figure that out.

707
00:43:32,980 --> 00:43:38,710
So what we'll do is we'll say okay B is IJ remember B is ij.

708
00:43:38,890 --> 00:43:44,950
But there is no comma here because we are dealing with only a one matrix or only one tensor.

709
00:43:44,950 --> 00:43:47,170
So the output is going to be GI.

710
00:43:47,200 --> 00:43:47,860
That's all.

711
00:43:47,860 --> 00:43:50,410
So and then you pass in a.

712
00:43:50,440 --> 00:43:53,500
So you run that we get this error.

713
00:43:53,500 --> 00:43:56,050
Expect input to have rank two but got one.

714
00:43:56,380 --> 00:43:59,140
While looking at this you see we put A instead of B.

715
00:43:59,140 --> 00:44:02,440
So when you replace and put B you find that now it works.

716
00:44:02,440 --> 00:44:05,470
So this here has been transposed.

717
00:44:05,470 --> 00:44:07,720
Notice how we have 29030.

718
00:44:07,720 --> 00:44:09,940
And here we have 29030.

719
00:44:10,330 --> 00:44:12,910
Um 368 negative two 2368.

720
00:44:12,910 --> 00:44:13,660
Negative two two.

721
00:44:13,690 --> 00:44:14,260
So that's it.

722
00:44:14,290 --> 00:44:20,440
We've, we've um, simply gotten the transpose of our input matrix for the next.

723
00:44:20,440 --> 00:44:23,230
We'll look at the element wise multiplication.

724
00:44:23,230 --> 00:44:24,190
So let's come.

725
00:44:24,320 --> 00:44:25,700
One copy.

726
00:44:25,910 --> 00:44:34,910
Um, A and B again where we have A and B, we copy that, we get down and then simply paste that out.

727
00:44:34,910 --> 00:44:39,890
Remember since this element wise multiplication this two must have the exact same shape.

728
00:44:39,890 --> 00:44:42,230
So let's take this off.

729
00:44:42,710 --> 00:44:46,430
Take this off, take this off.

730
00:44:46,430 --> 00:44:47,960
And that's fine.

731
00:44:47,960 --> 00:44:51,080
So now we have two three by four matrices.

732
00:44:51,080 --> 00:44:55,880
If we do the usual element wise multiplication a times b.

733
00:44:56,800 --> 00:45:03,100
Then you should have, obviously, for each and every position, the product of the two elements.

734
00:45:03,100 --> 00:45:07,210
So if you take this negative two times six we should have -12.

735
00:45:07,210 --> 00:45:07,990
So that's it.

736
00:45:07,990 --> 00:45:12,100
Now for the with the end sum operator we could do n sum.

737
00:45:12,250 --> 00:45:17,140
Now we have for a a is ij and then b must be ij.

738
00:45:17,140 --> 00:45:20,410
Because we said the they should have the same exact same shape.

739
00:45:20,410 --> 00:45:23,590
And then the output should also be ij.

740
00:45:23,590 --> 00:45:26,560
So let's run that and see what we get.

741
00:45:26,560 --> 00:45:29,530
We have ij ij expecting two.

742
00:45:29,560 --> 00:45:29,920
Okay.

743
00:45:29,920 --> 00:45:33,910
So we we forgot to put A and B here run that again.

744
00:45:34,120 --> 00:45:38,890
And now our output as you could see from here is exactly the same output we got from here.

745
00:45:38,890 --> 00:45:42,070
So we have 450 406 and so on and so forth.

746
00:45:42,070 --> 00:45:47,560
So we see we have exact same output and that's how we obtain this element wise multiplication.

747
00:45:47,560 --> 00:45:51,820
Let's now see what happens when we have say 3D tensors.

748
00:45:51,820 --> 00:45:56,110
So let's get back again here we just duplicate all this.

749
00:45:56,110 --> 00:46:01,450
Well let's just duplicate all this copy paste and send this just up right here.

750
00:46:01,450 --> 00:46:04,810
We have now this um 3D tensor.

751
00:46:04,810 --> 00:46:06,850
So here we have two.

752
00:46:07,590 --> 00:46:10,830
We add a batch dimension, we have two by three by four.

753
00:46:10,830 --> 00:46:14,550
So we have two, um, three by four tensors.

754
00:46:14,550 --> 00:46:15,990
So this is the first one.

755
00:46:15,990 --> 00:46:17,460
And then this is the second one.

756
00:46:17,460 --> 00:46:18,870
So this is the this is a.

757
00:46:18,870 --> 00:46:29,670
Now here we have a and then multiplied by here is multiplied by the b which is two four by five tensors.

758
00:46:29,670 --> 00:46:32,160
So this are the two four by five tensors.

759
00:46:32,160 --> 00:46:36,870
And this obviously is going to give us two three by five tensors.

760
00:46:36,870 --> 00:46:42,900
Now just as we had seen already with a, with a usual or with the usual matrix multiplication, we had

761
00:46:42,900 --> 00:46:45,360
ijk which gave us IK.

762
00:46:45,570 --> 00:46:53,040
Here we're going to have b I j b j k and we're just going to give us b I k.

763
00:46:53,040 --> 00:46:56,430
So the only thing we're going to add here is simply just this b.

764
00:46:56,940 --> 00:47:00,870
Let's get back and try to um repeat that.

765
00:47:00,870 --> 00:47:02,130
Let's get back here.

766
00:47:02,130 --> 00:47:05,850
We had this um a and B hope it's the exact same.

767
00:47:05,850 --> 00:47:06,960
No that's not the same.

768
00:47:06,960 --> 00:47:10,290
Let's get back to where we computed the matrix multiplication.

769
00:47:10,380 --> 00:47:11,070
There we go.

770
00:47:11,070 --> 00:47:12,330
We had this here.

771
00:47:12,780 --> 00:47:15,660
Um, let's just copy all this.

772
00:47:15,660 --> 00:47:16,920
So that's it.

773
00:47:17,190 --> 00:47:20,760
And instead of this here, we're going to put this out okay.

774
00:47:20,760 --> 00:47:27,570
So now we have a, we have a which is going to be made up of this tool two of this.

775
00:47:27,570 --> 00:47:29,940
So um, let's get back.

776
00:47:29,940 --> 00:47:30,990
There we go.

777
00:47:32,550 --> 00:47:33,780
Get from here.

778
00:47:33,780 --> 00:47:34,680
And that's fine.

779
00:47:35,370 --> 00:47:36,180
So that's it.

780
00:47:36,180 --> 00:47:37,800
So here we have this.

781
00:47:37,800 --> 00:47:39,570
And then we repeat this.

782
00:47:39,570 --> 00:47:43,650
So let's just repeat this piece that out.

783
00:47:43,650 --> 00:47:44,730
And that's fine.

784
00:47:44,730 --> 00:47:48,060
So now we have we open this up here.

785
00:47:48,270 --> 00:47:51,810
And then we close this at the end.

786
00:47:51,810 --> 00:47:53,070
We close this right here.

787
00:47:53,250 --> 00:47:58,620
So now that we have this uh our 3D tensor we repeat the same for B.

788
00:47:59,130 --> 00:48:00,030
There we go.

789
00:48:00,030 --> 00:48:03,780
We have a and then b and we print out their shapes.

790
00:48:03,780 --> 00:48:13,980
So let's now do insum and then we have uh rather we have b I j and then we have b j k b j k.

791
00:48:13,980 --> 00:48:16,890
And then we now have b I k.

792
00:48:16,890 --> 00:48:19,170
So let's run that and see what we get.

793
00:48:19,170 --> 00:48:23,160
So here we have a b c we have this output.

794
00:48:23,160 --> 00:48:28,230
Um it's obviously supposed to be the same output because there are same uh matrices or same tensors

795
00:48:28,230 --> 00:48:29,700
which we've repeated here.

796
00:48:29,700 --> 00:48:33,030
We have 33, 69, 77 negative six.

797
00:48:33,030 --> 00:48:40,890
Exactly as we expect a practical case of where we could apply or make use of the ensemble operator is

798
00:48:40,890 --> 00:48:42,510
with the transformer model.

799
00:48:42,510 --> 00:48:48,690
So right here we have the softmax of QQ transpose divided by square root of DK times v.

800
00:48:48,690 --> 00:48:51,300
Anyway, you don't need to understand what's going on.

801
00:48:51,300 --> 00:48:57,540
Just take note of the fact that we have k or k transpose, and that we want to multiply KR by k transpose

802
00:48:57,540 --> 00:48:59,310
using the Insum operator.

803
00:48:59,310 --> 00:49:04,020
So it's the same as just saying we want to multiply a by b transpose.

804
00:49:04,500 --> 00:49:08,190
So let's say we have a which is this 3D tensor.

805
00:49:08,190 --> 00:49:12,690
Let's copy that and paste out here we have a which is this 3D tensor.

806
00:49:12,690 --> 00:49:19,470
And then we we we want to do a um times a transpose.

807
00:49:19,470 --> 00:49:23,070
So we want to have a um times a transpose.

808
00:49:23,370 --> 00:49:25,620
So now we're multiplying a with a.

809
00:49:25,620 --> 00:49:29,640
And then we have transpose B set to true.

810
00:49:29,640 --> 00:49:36,420
So what we're saying here is we want this to be transposed before we multiply with a let's print out

811
00:49:36,420 --> 00:49:38,910
this and see what we obtain.

812
00:49:40,100 --> 00:49:41,090
There we go.

813
00:49:41,090 --> 00:49:43,610
You see, we have our expected output.

814
00:49:43,610 --> 00:49:47,570
Now let's suppose that we wanted to use the Or.

815
00:49:47,570 --> 00:49:49,370
Let's use the Insum operator.

816
00:49:49,370 --> 00:49:53,810
So right here we would have print and sum.

817
00:49:53,810 --> 00:50:02,330
And then we simply specify that here we're going to have because let's let's print out a um a shape.

818
00:50:02,900 --> 00:50:04,340
Let's print this out here.

819
00:50:05,120 --> 00:50:06,800
Um let's print out a shape.

820
00:50:06,800 --> 00:50:11,000
So as we're saying here we're going to have two by three by four.

821
00:50:11,000 --> 00:50:15,200
So it's b I j there we have big.

822
00:50:15,290 --> 00:50:18,500
And then for the next one is going to be b.

823
00:50:18,500 --> 00:50:28,910
But j I or rather b um j k because this, this could be two different matrices or two different tensors.

824
00:50:28,910 --> 00:50:35,120
Now before putting out the string let's just um repeat or let's just put out the shapes here so it's

825
00:50:35,120 --> 00:50:35,630
clearer.

826
00:50:35,630 --> 00:50:38,240
So here we could have 234.

827
00:50:38,240 --> 00:50:40,370
And then we could multiply this.

828
00:50:40,370 --> 00:50:46,700
We could multiply this by um two or the transpose of 234.

829
00:50:46,700 --> 00:50:53,180
Now what's interesting to note is the fact that because this column is already fixed, it means that

830
00:50:53,180 --> 00:50:55,640
here too, it has to be fixed.

831
00:50:55,640 --> 00:50:59,960
Because when you transpose this we're going to have two, four, three.

832
00:50:59,960 --> 00:51:02,480
We constrain that the batch, uh remains fixed.

833
00:51:02,480 --> 00:51:04,190
So when this is transposed.

834
00:51:04,190 --> 00:51:09,860
So this is going to be now or let let's just put this out as the transpose.

835
00:51:11,000 --> 00:51:15,350
Let's say the transpose multiply by the transpose of this.

836
00:51:16,010 --> 00:51:20,390
So after transposing let's copy this paste this out here.

837
00:51:20,390 --> 00:51:24,800
After transposing we expect to get 243.

838
00:51:25,310 --> 00:51:26,360
Let's take that off.

839
00:51:26,390 --> 00:51:28,010
We get back here okay.

840
00:51:28,010 --> 00:51:30,740
So we have 234 by 243.

841
00:51:30,740 --> 00:51:36,980
So we have to ensure that this number of columns matches uh with this um number of columns for the first

842
00:51:36,980 --> 00:51:37,880
matrix.

843
00:51:37,970 --> 00:51:42,050
Whereas this three year doesn't need to match with the other.

844
00:51:42,050 --> 00:51:47,210
So we could have um two, three, four and then um, 234.

845
00:51:47,210 --> 00:51:51,140
And here after transpose is going to be like uh, two 430.

846
00:51:51,140 --> 00:51:53,030
Anyways this for this for match.

847
00:51:53,030 --> 00:51:53,900
So that's fine.

848
00:51:53,900 --> 00:51:59,240
So that said, what we are seeing is because this three could be any value.

849
00:51:59,240 --> 00:52:01,310
It could be one, it could be whatever value.

850
00:52:01,610 --> 00:52:09,260
Um, we have to be careful with the way we, we, we note that because in this case we took 234 uh,

851
00:52:09,260 --> 00:52:14,300
two three 4th May be tempted to, to use the exact same, um letters for those two.

852
00:52:14,300 --> 00:52:24,380
So getting back here we have I, um j k this is, this is I, this is J and then this is k, and then

853
00:52:24,380 --> 00:52:30,830
the transpose of that's multiplied by the transpose of um 254.

854
00:52:30,830 --> 00:52:39,590
So now we have I again, that's the same I or let's say batch batch batch I, batch I j.

855
00:52:40,070 --> 00:52:41,780
And then here we also have batch.

856
00:52:42,530 --> 00:52:43,580
There we go.

857
00:52:43,580 --> 00:52:45,470
And then now we have k.

858
00:52:45,470 --> 00:52:49,640
So we're calling this k because this five could be whatever.

859
00:52:49,640 --> 00:52:50,690
It must not be.

860
00:52:50,870 --> 00:52:52,940
Um exactly this three.

861
00:52:52,940 --> 00:52:53,870
So it must not be I.

862
00:52:53,900 --> 00:52:54,980
So we have k.

863
00:52:54,980 --> 00:52:59,630
And then for the four we have j because it must match.

864
00:52:59,630 --> 00:53:04,580
Remember after we transpose let's let's print this out again.

865
00:53:04,580 --> 00:53:06,350
This is what happens after we transpose.

866
00:53:06,350 --> 00:53:09,980
After we transpose we'll be having j k and this j.

867
00:53:10,010 --> 00:53:11,390
Now we match with this j.

868
00:53:11,390 --> 00:53:14,270
So it's important that we take note of that.

869
00:53:14,510 --> 00:53:15,380
Let's take that off.

870
00:53:15,380 --> 00:53:19,040
And then now we have a and a.

871
00:53:19,070 --> 00:53:20,060
So that's it.

872
00:53:20,060 --> 00:53:21,950
Let's run this and see what we get.

873
00:53:21,950 --> 00:53:28,490
You see we have 138 um 16 104 and so on and so forth.

874
00:53:28,520 --> 00:53:30,710
Well actually this is the reduced sum.

875
00:53:30,710 --> 00:53:34,760
So let's, let's go ahead and put the arrow and then say we want to have b.

876
00:53:34,880 --> 00:53:41,150
Now the, the this is very important because you have to be careful with the way this is going to be

877
00:53:41,150 --> 00:53:43,070
or the output is going to be generated.

878
00:53:43,070 --> 00:53:50,360
Here we have B, we have I and then we have k because this j and this j is going to be eliminated.

879
00:53:50,360 --> 00:53:57,620
So we have by j bc and our by k slightly different from the usual matrix multiplication because here

880
00:53:57,620 --> 00:54:03,230
the second uh matrix or second tensor is going to be transposed.

881
00:54:03,230 --> 00:54:04,250
So that's it.

882
00:54:04,250 --> 00:54:06,740
So run that see what we get.

883
00:54:06,740 --> 00:54:11,150
You see we have exact same output as uh what we had before here.

884
00:54:11,150 --> 00:54:14,210
So 69 852 821 zero.

885
00:54:14,210 --> 00:54:14,720
That's it.

886
00:54:15,080 --> 00:54:16,490
Um, exactly what we expect.

887
00:54:16,490 --> 00:54:17,960
So that's it for the sum.

888
00:54:17,960 --> 00:54:18,590
Operator.

889
00:54:18,590 --> 00:54:21,920
Hope this, um, section was was clear.

890
00:54:21,920 --> 00:54:27,530
And see you in the next section where we shall look at other, uh, common methods in TensorFlow.
