1
00:00:00,230 --> 00:00:05,030
For the section on math operations, we shall head over to the documentation.

2
00:00:05,030 --> 00:00:09,920
And then just right here to the left we shall look for TensorFlow math.

3
00:00:09,920 --> 00:00:13,160
So let's scroll down and get this.

4
00:00:13,160 --> 00:00:13,730
Here we go.

5
00:00:13,730 --> 00:00:15,110
We have TensorFlow math.

6
00:00:15,230 --> 00:00:20,090
You could check out this very first method we have here out of all these different methods.

7
00:00:20,090 --> 00:00:25,160
So here are different math functions which you could make use of very easily.

8
00:00:25,160 --> 00:00:32,900
And anytime you have any doubt with how a specific method is being used, you could head over to documentation,

9
00:00:32,900 --> 00:00:34,610
select one like this.

10
00:00:34,610 --> 00:00:37,070
Like this is absolute um function.

11
00:00:37,190 --> 00:00:37,910
Select that.

12
00:00:37,910 --> 00:00:41,780
And then to the right you would have that function definition.

13
00:00:41,780 --> 00:00:43,940
You would have some example.

14
00:00:43,940 --> 00:00:51,020
And then you would also have um a more detailed explanation of what um, the different arguments the

15
00:00:51,020 --> 00:00:55,160
function takes in mean and also what the function returns.

16
00:00:55,160 --> 00:00:59,900
That said, um, the absolute function takes an x.

17
00:00:59,900 --> 00:01:01,970
Um, so we'll get back to the code right here.

18
00:01:01,970 --> 00:01:08,180
So let's say we have um TensorFlow absolute function which takes in x.

19
00:01:08,180 --> 00:01:10,940
In this case let's say x is let's define x.

20
00:01:10,940 --> 00:01:15,020
So here we have x uh which is simply a constant.

21
00:01:15,020 --> 00:01:18,320
And this constant is c 0.2.

22
00:01:18,350 --> 00:01:25,550
Now if we have 0.2 and we pass this into the absolute value function, then what we get as output,

23
00:01:25,550 --> 00:01:30,800
what we get as output is the same or the exact same 0.2.

24
00:01:31,790 --> 00:01:35,690
Now let's change this to -0.2 and see what we get.

25
00:01:36,260 --> 00:01:39,200
You see here we have still 0.2.

26
00:01:39,230 --> 00:01:46,070
Now what this tells us is um, the absolute value, what the absolute value function does is it takes

27
00:01:46,070 --> 00:01:50,210
in an input x and if so it takes in x.

28
00:01:50,210 --> 00:01:59,240
If x is less than zero what happens is this x uh becomes negative x you see.

29
00:01:59,240 --> 00:02:08,930
And then um if x is greater than if x is greater than zero then that x remains the same.

30
00:02:08,930 --> 00:02:11,960
So you simply say remains the same.

31
00:02:11,960 --> 00:02:15,770
So that's um, exactly what the absolute value function does.

32
00:02:15,770 --> 00:02:19,130
Now you could, you could also take in a 1D array.

33
00:02:19,130 --> 00:02:20,930
So let's say this is 1D.

34
00:02:20,960 --> 00:02:26,270
We have two minus one 30.1 and zero.

35
00:02:26,270 --> 00:02:28,310
Let's run that and see what we obtain.

36
00:02:28,400 --> 00:02:30,920
You see we have two one.

37
00:02:30,920 --> 00:02:33,770
So the negative one has tends to has turned to one.

38
00:02:33,770 --> 00:02:38,180
The three is remains the same 0.1 remains the same and zero remains the same.

39
00:02:38,180 --> 00:02:41,660
Now let's say we want to have your -0.1.

40
00:02:41,660 --> 00:02:42,710
Run that again.

41
00:02:43,040 --> 00:02:50,180
So we have the exact same number but with a with the difference that whenever we have a negative value

42
00:02:50,180 --> 00:02:51,980
that negative sign is taken off.

43
00:02:51,980 --> 00:02:58,730
Now getting back to the documentation, you would see that we um apart from real numbers we could also

44
00:02:58,730 --> 00:03:00,470
take in complex numbers.

45
00:03:00,470 --> 00:03:03,500
So you see you see very simple examples here.

46
00:03:03,710 --> 00:03:05,450
Um, you could take in a complex number.

47
00:03:05,450 --> 00:03:11,990
And essentially what um, this does is like, uh, when it gets a complex number, a plus BG.

48
00:03:12,980 --> 00:03:19,760
The absolute value of that complex number a plus b is a squared plus b squared all of that square root.

49
00:03:19,820 --> 00:03:21,830
So you see the simple example here.

50
00:03:21,860 --> 00:03:25,490
Now let's let's just go ahead and and test this out.

51
00:03:25,490 --> 00:03:33,170
So let's say we have um x or let's just copy this um copy that and then paste it out here.

52
00:03:33,170 --> 00:03:40,520
So let's say we have x equal two x equal two plus um 3g.

53
00:03:40,550 --> 00:03:41,270
There we go.

54
00:03:41,270 --> 00:03:43,580
So we have x equal two plus three j.

55
00:03:43,580 --> 00:03:47,030
And we want to get the absolute value of that x.

56
00:03:47,030 --> 00:03:48,800
You see we have 3.6.

57
00:03:48,800 --> 00:03:51,560
Now to verify that this matches with our formula.

58
00:03:51,560 --> 00:03:55,400
Let's do two or let's say TensorFlow square root.

59
00:03:55,400 --> 00:04:01,130
So this is another TensorFlow method TensorFlow square root of two to the power of two.

60
00:04:01,160 --> 00:04:07,460
That's two square plus um two square plus three square.

61
00:04:07,490 --> 00:04:09,380
That's three three.

62
00:04:09,410 --> 00:04:14,630
Here we have three square or to the power of two that's fine.

63
00:04:14,630 --> 00:04:16,370
So we have two square plus three square.

64
00:04:16,370 --> 00:04:17,300
And then we get a square root.

65
00:04:17,300 --> 00:04:19,460
So let's run that and see what we get.

66
00:04:19,460 --> 00:04:20,780
We get an error.

67
00:04:20,960 --> 00:04:27,710
We're told here that the value for the attribute of int32 is not in the list of allowed values.

68
00:04:27,710 --> 00:04:33,590
So let's let's take this to 2.03.0.

69
00:04:33,590 --> 00:04:36,380
Run that again and see what we get.

70
00:04:36,380 --> 00:04:36,980
There we go.

71
00:04:36,980 --> 00:04:41,060
So as you could see we have 3.6055512.

72
00:04:41,060 --> 00:04:43,040
And this is that same as this.

73
00:04:43,040 --> 00:04:44,450
So that's it.

74
00:04:44,450 --> 00:04:51,920
You you you see that this when we get a complex number suffices to do a squared plus b squared and square

75
00:04:51,920 --> 00:04:52,280
root.

76
00:04:52,280 --> 00:04:53,390
And that's fine.

77
00:04:53,390 --> 00:04:55,460
Now we'll move on to the next method.

78
00:04:55,460 --> 00:04:57,200
We'll look at very simple methods.

79
00:04:57,200 --> 00:04:59,330
So let's say we have the addition method.

80
00:04:59,330 --> 00:05:04,310
So obviously you should um know how this addition method works.

81
00:05:04,700 --> 00:05:06,080
Um because it's just simple addition.

82
00:05:06,080 --> 00:05:09,680
So it returns x plus y and it's element wise addition.

83
00:05:09,680 --> 00:05:14,120
So obviously we would expect x and y to be of the same shape.

84
00:05:14,540 --> 00:05:18,410
Um so yeah let's get back let's get back.

85
00:05:18,410 --> 00:05:20,060
And then let's take an example.

86
00:05:20,060 --> 00:05:25,820
Let's say we have x which is equal um TensorFlow constant.

87
00:05:26,300 --> 00:05:33,110
And then we say um 235 and seven.

88
00:05:33,110 --> 00:05:39,080
And then we have y TensorFlow constant TensorFlow constant.

89
00:05:40,220 --> 00:05:46,730
And then we have 77217721.

90
00:05:46,730 --> 00:05:47,960
There we go okay.

91
00:05:47,960 --> 00:05:51,590
So here we would have TensorFlow add x y.

92
00:05:52,190 --> 00:05:54,920
So we should let's print that out.

93
00:05:55,490 --> 00:05:56,390
There we go.

94
00:05:56,390 --> 00:05:57,590
Let's print this out.

95
00:05:57,590 --> 00:06:02,090
We have um TensorFlow add x y.

96
00:06:02,120 --> 00:06:04,370
Now you see that we have two plus seven.

97
00:06:04,370 --> 00:06:06,020
That's nine three plus seven.

98
00:06:06,020 --> 00:06:07,790
That's ten five plus two.

99
00:06:07,790 --> 00:06:10,430
That's seven seven plus one that's eight.

100
00:06:10,430 --> 00:06:20,030
And then um as we said this two are expected to be of the same shape because obviously it's an element

101
00:06:20,030 --> 00:06:20,930
wise addition.

102
00:06:20,930 --> 00:06:25,340
Now what if instead of having this, we, we, we say we want to have one.

103
00:06:25,340 --> 00:06:26,870
Let's say what if we do one.

104
00:06:26,870 --> 00:06:29,120
We run that and see what we get.

105
00:06:29,120 --> 00:06:32,270
You see, it still works, although we don't have exact same shape.

106
00:06:32,270 --> 00:06:39,020
And the reason why this works is because just before adding up this two, three, five, seven with

107
00:06:39,020 --> 00:06:45,770
this one, this one is stretched out to match the shape of this two, three, five, seven.

108
00:06:45,770 --> 00:06:53,030
So this one now becomes one one, one one and one.

109
00:06:53,030 --> 00:06:53,720
So that's it.

110
00:06:53,720 --> 00:06:57,020
So if you run this again you'll see you have 3468.

111
00:06:58,210 --> 00:06:58,660
You see.

112
00:06:58,660 --> 00:06:58,960
Yeah.

113
00:06:58,960 --> 00:07:00,370
We have three, four, six, eight.

114
00:07:00,370 --> 00:07:01,060
That's it.

115
00:07:01,060 --> 00:07:04,060
So we get back to one, run that again.

116
00:07:04,330 --> 00:07:06,760
We still have the exact same output.

117
00:07:06,760 --> 00:07:15,430
So, um, although we said they should have the same shape, um, in some cases where we could broadcast

118
00:07:15,430 --> 00:07:21,670
the tensor with a smaller shape, then we could have the addition operation carried out without any

119
00:07:21,670 --> 00:07:22,420
errors.

120
00:07:22,420 --> 00:07:25,360
So that's it for our tensor flow math.

121
00:07:25,360 --> 00:07:31,150
So this tensor flow math add um we could also do the same with subtraction.

122
00:07:31,150 --> 00:07:35,470
So if you check below you should have subtraction multiplication.

123
00:07:35,470 --> 00:07:40,120
Remember it's element wise multiplication and element wise subtraction.

124
00:07:40,120 --> 00:07:41,650
So let's go to em.

125
00:07:41,650 --> 00:07:47,020
Here we have multiply um s we have subtract.

126
00:07:47,320 --> 00:07:48,670
Let's scroll down.

127
00:07:48,670 --> 00:07:49,660
We should have subtract.

128
00:07:49,660 --> 00:07:51,400
And then we also have divide.

129
00:07:51,400 --> 00:07:52,840
So let's get back to D.

130
00:07:52,870 --> 00:07:54,610
We have divide.

131
00:07:54,610 --> 00:07:55,630
So that's it.

132
00:07:55,630 --> 00:07:58,960
And you notice here that you have this divide and divide.

133
00:07:58,960 --> 00:07:59,830
No Nan.

134
00:08:00,560 --> 00:08:03,620
So let's check out what this divide Nolan does.

135
00:08:03,890 --> 00:08:05,120
Let's get back to the code.

136
00:08:05,120 --> 00:08:06,950
Well, let's just let's just check this out.

137
00:08:06,950 --> 00:08:08,300
You see, compute is saved.

138
00:08:08,300 --> 00:08:11,570
Divide which returns zero if the denominator is zero.

139
00:08:11,570 --> 00:08:13,160
So let's get back here.

140
00:08:13,160 --> 00:08:17,690
Let's say we have 2357 and then we have zero.

141
00:08:17,690 --> 00:08:21,650
And then we decide to have divide divide instead of add.

142
00:08:22,160 --> 00:08:26,690
You see here we have infinity infinity infinity infinity because we're dividing by zero.

143
00:08:26,690 --> 00:08:35,690
And so what we could do is if we say divide no, no, um no Nan run that.

144
00:08:37,110 --> 00:08:39,330
Well, this is let's let's get the exact name.

145
00:08:39,330 --> 00:08:41,880
So here we have um divide.

146
00:08:41,880 --> 00:08:42,570
No Nan.

147
00:08:42,570 --> 00:08:43,680
That's TensorFlow math.

148
00:08:43,680 --> 00:08:48,990
Well so far we had been using um this divide from TensorFlow itself.

149
00:08:48,990 --> 00:08:52,230
But we need to specify uh we're using from TensorFlow math.

150
00:08:52,230 --> 00:08:54,420
And TensorFlow math has divide no Nan.

151
00:08:54,420 --> 00:08:55,530
So let's run that.

152
00:08:55,530 --> 00:09:03,150
And you see we now have zeros because whenever we have an um an infinite output we turn this into zeros.

153
00:09:03,150 --> 00:09:08,340
Let's, let's let's change this and say we have 024 and five.

154
00:09:08,340 --> 00:09:10,560
Run that again and see what we get.

155
00:09:10,560 --> 00:09:15,780
You see this is zero, 1.51.25 and 1.5 uh, 1.4.

156
00:09:15,780 --> 00:09:18,450
If you take the divide off, run that again.

157
00:09:18,870 --> 00:09:23,190
You see we have infinity 1.5, 1.25 and 1.4.

158
00:09:23,190 --> 00:09:26,550
So that's it for this basic math operations.

159
00:09:27,240 --> 00:09:32,280
Before we move on to other math methods, let's consider the following example.

160
00:09:32,280 --> 00:09:37,560
So supposing we have this um tensor which we want to multiply by this other tensor.

161
00:09:37,560 --> 00:09:40,410
This is obviously uh one by four tensor.

162
00:09:40,410 --> 00:09:43,500
And here we have uh two by one tensor.

163
00:09:43,500 --> 00:09:49,890
In that case we would still apply the broadcasting similar with what we had seen already.

164
00:09:49,890 --> 00:09:55,650
So before we had two by three or rather two three.

165
00:09:55,650 --> 00:10:01,230
So this was a tensor two three um four and then five.

166
00:10:01,320 --> 00:10:12,930
And then when we when we multiply this by one, this one became this one year became one, one, one

167
00:10:12,930 --> 00:10:21,600
and then one such that when we multiply this two, three, four, five by one, we're actually multiplying

168
00:10:21,600 --> 00:10:25,770
two, three, four five by 1111.

169
00:10:25,980 --> 00:10:33,030
Now that said, um, for this example here, we would still carry out this broadcasting.

170
00:10:33,030 --> 00:10:40,320
So we would um, repeat this two, three, four, five twice because here we have two rows.

171
00:10:40,320 --> 00:10:42,060
So here we have only one row.

172
00:10:42,060 --> 00:10:48,330
We're just going to repeat this so that such that we have 234.

173
00:10:49,030 --> 00:10:50,230
Five.

174
00:10:50,960 --> 00:10:51,830
There we go.

175
00:10:51,830 --> 00:10:55,970
So we now have two, three, four, five repeated twice.

176
00:10:55,970 --> 00:10:57,200
That's row wise.

177
00:10:57,200 --> 00:11:01,910
And then this one three is also going to be repeated but column wise.

178
00:11:01,910 --> 00:11:05,150
So let's um let's take all this off.

179
00:11:05,150 --> 00:11:06,620
Let's take this once off.

180
00:11:07,480 --> 00:11:08,470
There we go.

181
00:11:08,470 --> 00:11:15,880
We take this off, we take this off, and then we now repeat this one three, four times.

182
00:11:15,880 --> 00:11:21,490
So we have one three, one three and then one three.

183
00:11:21,820 --> 00:11:26,440
So you see now that we could multiply this two um element wise.

184
00:11:26,440 --> 00:11:31,810
And after multiplying this two obviously this should give us something like um this is two.

185
00:11:31,840 --> 00:11:34,120
So all of this on the top remains the same.

186
00:11:34,120 --> 00:11:37,480
So we have 234, five.

187
00:11:37,480 --> 00:11:41,560
And then what we have down is um two times three.

188
00:11:41,560 --> 00:11:42,550
That's six.

189
00:11:42,670 --> 00:11:43,870
Three times three.

190
00:11:43,870 --> 00:11:44,680
That's nine.

191
00:11:44,680 --> 00:11:46,990
Four times three, that's 12.

192
00:11:47,170 --> 00:11:49,450
Um five times three, that's 15.

193
00:11:49,450 --> 00:11:50,800
So this is now our output.

194
00:11:50,800 --> 00:11:54,730
Now let's get back to the code and see if, um, this is the output we're going to have.

195
00:11:55,090 --> 00:11:58,240
So we'll get back here and we have x.

196
00:11:58,510 --> 00:12:02,350
Let's take that off x equal um our constant.

197
00:12:03,430 --> 00:12:06,280
Well let's say we have let's get back here.

198
00:12:06,280 --> 00:12:08,770
We have 2345 and then one three.

199
00:12:08,770 --> 00:12:10,720
So we have 2345.

200
00:12:10,720 --> 00:12:14,800
And then 132345.

201
00:12:14,920 --> 00:12:20,680
And then we have y which is um another TensorFlow tensor.

202
00:12:21,520 --> 00:12:24,190
And then here is instead one three.

203
00:12:24,190 --> 00:12:27,340
So because we're going row wise we will have one.

204
00:12:27,340 --> 00:12:28,780
So this is actually 2D.

205
00:12:28,780 --> 00:12:30,070
So we have one.

206
00:12:30,070 --> 00:12:32,320
And then we have three.

207
00:12:32,350 --> 00:12:35,020
Whereas here this 2D is column wise.

208
00:12:35,020 --> 00:12:38,380
So we have one two or we have 2345.

209
00:12:38,380 --> 00:12:39,160
So that's it.

210
00:12:39,190 --> 00:12:41,920
Now let's get back and do TensorFlow.

211
00:12:42,010 --> 00:12:48,310
Let's print that out TensorFlow multi or math multiply.

212
00:12:48,610 --> 00:12:51,490
And then we specify x and y.

213
00:12:51,490 --> 00:12:54,040
So let's run that and see what we get.

214
00:12:55,120 --> 00:12:56,350
Increase the cells.

215
00:12:56,350 --> 00:12:57,190
There we go.

216
00:12:57,190 --> 00:13:01,120
You see we have 234569 1215.

217
00:13:01,150 --> 00:13:03,970
Exactly as we had gotten already from this board.

218
00:13:04,780 --> 00:13:06,340
Let's continue with other methods.

219
00:13:06,340 --> 00:13:07,390
We have.

220
00:13:07,390 --> 00:13:09,400
For example maximum.

221
00:13:09,400 --> 00:13:11,200
So let's click on maximum.

222
00:13:11,200 --> 00:13:15,070
You will find that with maximum um it's simple.

223
00:13:15,340 --> 00:13:17,290
We're going to compare two values.

224
00:13:17,290 --> 00:13:19,960
Again element wise we compare two values.

225
00:13:19,960 --> 00:13:23,140
If x is greater than y then the output is going to be x.

226
00:13:23,140 --> 00:13:27,100
And if x is less than y um the output will be y.

227
00:13:27,100 --> 00:13:32,290
We just comparing and seeing the the one which is maximum is the one which um, takes that position.

228
00:13:32,290 --> 00:13:36,820
So let's take an example like here we have 0000.

229
00:13:36,820 --> 00:13:43,030
And then negative two 025 at this zero position the maximum here is zero.

230
00:13:43,030 --> 00:13:44,800
So it's normal that the output is zero.

231
00:13:44,800 --> 00:13:49,060
At this um position the maximum is zero obviously is the same.

232
00:13:49,060 --> 00:13:51,100
So um zero.

233
00:13:51,130 --> 00:13:52,540
Yeah the maximum is two.

234
00:13:52,570 --> 00:13:53,500
So we have two.

235
00:13:53,500 --> 00:13:56,680
Last position we have zero and five.

236
00:13:56,680 --> 00:13:57,490
The max is five.

237
00:13:57,490 --> 00:13:58,990
So here we have five.

238
00:13:59,470 --> 00:14:01,870
It also supports the broadcast semantics.

239
00:14:01,870 --> 00:14:09,400
So saying you want to compare negative five 000 with negative three is the same as comparing negative

240
00:14:09,400 --> 00:14:15,550
five 000 with negative three negative three negative three and negative three.

241
00:14:15,550 --> 00:14:21,430
So obviously the maximum um the value the highest value will be negative three.

242
00:14:21,430 --> 00:14:25,240
But for the rest will be zeros because zero is greater than negative three.

243
00:14:25,240 --> 00:14:26,080
So that's it.

244
00:14:26,260 --> 00:14:30,160
And that's it for the maximum we also have the minimum.

245
00:14:30,160 --> 00:14:33,940
So minimum obviously is going to be uh just the opposite of maximum.

246
00:14:33,940 --> 00:14:38,080
So here instead we want to get the value with a or the smaller value.

247
00:14:38,080 --> 00:14:42,100
So when comparing um element wise we just want to get the smaller value.

248
00:14:42,100 --> 00:14:42,790
That's it.

249
00:14:42,790 --> 00:14:44,080
Getting back to the code.

250
00:14:44,080 --> 00:14:46,870
You will try this with our previous example.

251
00:14:46,870 --> 00:14:50,050
You find that we have 23453345.

252
00:14:50,050 --> 00:14:53,380
Now let's get back to our board and try to justify this answer.

253
00:14:53,380 --> 00:14:57,790
So after broadcasting we have this output for X and we have this output for y.

254
00:14:57,820 --> 00:15:04,780
Now if it's a maximum then um at this position we have two because comparing two and one the max is

255
00:15:04,780 --> 00:15:05,380
two.

256
00:15:05,410 --> 00:15:07,210
Then the next is three.

257
00:15:07,210 --> 00:15:08,770
Well it's going to be 2345.

258
00:15:08,770 --> 00:15:13,270
Obviously because all this are greater than one which is what we have.

259
00:15:13,420 --> 00:15:14,440
Um right here.

260
00:15:14,440 --> 00:15:16,870
And then for the next we have two and three.

261
00:15:16,900 --> 00:15:21,040
The max there is three, um, three and three we have three.

262
00:15:21,160 --> 00:15:22,660
Next we have four.

263
00:15:22,660 --> 00:15:24,790
And then finally we have five.

264
00:15:24,790 --> 00:15:28,810
So this makes sense that this is the output we are getting.

265
00:15:29,200 --> 00:15:33,940
We are now going to move to the next method which is the arg max method.

266
00:15:34,060 --> 00:15:42,430
So this arg max method is similar to the max method, but with the difference that here we aren't tracking

267
00:15:42,430 --> 00:15:50,500
the value which has the or the maximum value where instead tracking the position of the maximum value.

268
00:15:50,500 --> 00:15:52,510
So let's take a simple example.

269
00:15:52,900 --> 00:16:00,730
Um, you have this here, this a let's copy this you and paste our here so we could get the ARG Max.

270
00:16:00,730 --> 00:16:01,630
There we go.

271
00:16:01,630 --> 00:16:06,910
We have um TensorFlow arg max or math arg max.

272
00:16:07,530 --> 00:16:15,000
We have a and then we run that you see from here that the value or the output is two.

273
00:16:15,030 --> 00:16:22,860
Now the reason why we having two is because the value or the, the max value we have here is found at

274
00:16:22,860 --> 00:16:23,910
position two.

275
00:16:23,940 --> 00:16:27,030
Remember, let's, um, get back here.

276
00:16:27,600 --> 00:16:30,630
If we want to specify each and every index, we will have zero.

277
00:16:30,630 --> 00:16:31,770
We have one.

278
00:16:32,070 --> 00:16:33,000
Um, let's get back here.

279
00:16:33,000 --> 00:16:37,020
We have two, we have three, and then we have four.

280
00:16:37,020 --> 00:16:39,420
Now the maximum value is 30.

281
00:16:39,420 --> 00:16:41,460
And it turns out that is found at position two.

282
00:16:41,490 --> 00:16:48,060
So that's why we have that if we just um, if we have mean then because the smallest value we have two

283
00:16:48,090 --> 00:16:50,160
is two, then we should have an output of zero.

284
00:16:50,160 --> 00:16:51,930
So let's take this off.

285
00:16:51,930 --> 00:16:53,250
Run that again.

286
00:16:53,250 --> 00:16:55,290
And you see we have an output of zero.

287
00:16:55,290 --> 00:17:03,120
So essentially the arg max arg min um help you trace the position or the index uh, on which we have

288
00:17:03,120 --> 00:17:04,740
the max or the minimum value.

289
00:17:05,100 --> 00:17:10,530
Now, if instead we have a 2D tensor, then doing math.

290
00:17:10,560 --> 00:17:19,980
Arg max and then passing in our our tensor, then specifying the axis to be zero, we would get an output

291
00:17:19,980 --> 00:17:22,500
of 32030.

292
00:17:22,500 --> 00:17:24,960
Now let's explain why we have this output.

293
00:17:25,230 --> 00:17:29,040
Because we've set the axis to zero.

294
00:17:29,070 --> 00:17:35,520
It simply means that we are going to be carrying out the comparisons across the rows.

295
00:17:35,520 --> 00:17:38,610
So um, that will be across the rows.

296
00:17:38,610 --> 00:17:43,680
Now if the axis is set to one, then it's going to be across the columns.

297
00:17:43,860 --> 00:17:51,360
That said, for each and every row that is um, for this row, remember we have the zeroth, first,

298
00:17:51,360 --> 00:17:55,230
second and third row or we have this for different rows.

299
00:17:55,230 --> 00:17:59,670
We are going to compare values at each and every position.

300
00:17:59,670 --> 00:18:06,660
So um, for this position right here for the zeroth position, we're going to compare this value with

301
00:18:06,660 --> 00:18:10,560
this value with this value and with this value.

302
00:18:10,560 --> 00:18:16,710
So this is essentially comparing two with zero with zero and with seven.

303
00:18:16,710 --> 00:18:23,220
And we're comparing across um these rows uh, because we've specified axis to be zero.

304
00:18:23,220 --> 00:18:31,650
And so that said the max value we have here is seven but seven that's the seven year but seven is found

305
00:18:31,650 --> 00:18:33,330
at the position three.

306
00:18:33,330 --> 00:18:34,920
That's why we have three.

307
00:18:35,250 --> 00:18:41,310
And then um, for the next we have one one, five and three.

308
00:18:41,340 --> 00:18:44,250
The max is five which is found at position two.

309
00:18:44,880 --> 00:18:47,790
And then for the next we have 9710.

310
00:18:47,790 --> 00:18:50,010
Max is nine at position zero.

311
00:18:50,400 --> 00:18:54,690
And then we have 6329 max is nine position three.

312
00:18:55,380 --> 00:18:58,080
And finally we have 5200.

313
00:18:58,080 --> 00:19:01,110
Max is five at position zero.

314
00:19:01,110 --> 00:19:02,160
So that's it.

315
00:19:02,160 --> 00:19:06,720
That's how we obtain um 32030 as we got here.

316
00:19:06,720 --> 00:19:12,750
Now you could pause at this level, change the axis to one and try to figure out what the output would

317
00:19:12,750 --> 00:19:15,060
be and compare with the solution we're going to have.

318
00:19:15,180 --> 00:19:20,520
So let's run this um, while okay we have 2213.

319
00:19:20,910 --> 00:19:23,820
So let's figure out how we have 2213.

320
00:19:23,850 --> 00:19:25,290
The axis has been sent to one.

321
00:19:25,290 --> 00:19:28,050
So we carry out comparison across the different columns.

322
00:19:28,050 --> 00:19:35,700
So um, we have this here, we have this and we have this and we have this.

323
00:19:35,700 --> 00:19:41,790
So we instead compare here compare here, compare across the different columns.

324
00:19:41,790 --> 00:19:43,260
Compare across the different columns.

325
00:19:43,260 --> 00:19:46,170
So 21965.

326
00:19:46,170 --> 00:19:49,920
Then the max is nine and is found at position two.

327
00:19:50,130 --> 00:19:52,500
Then we have 01732.

328
00:19:52,500 --> 00:19:54,720
Max is seven found at position two.

329
00:19:54,930 --> 00:19:58,170
Then again we have 05120.

330
00:19:58,170 --> 00:20:00,420
Max is five found at position one.

331
00:20:00,420 --> 00:20:03,090
Finally we have 73090.

332
00:20:03,090 --> 00:20:05,820
Max is nine found at position three.

333
00:20:05,820 --> 00:20:09,090
So that's exactly how we have 2213.

334
00:20:09,090 --> 00:20:13,530
Now obviously you could change this to mean and you would have something similar.

335
00:20:13,530 --> 00:20:17,760
So that's how we we make use of this arg max um function.

336
00:20:17,760 --> 00:20:22,350
Well this should be argmin arg min.

337
00:20:22,350 --> 00:20:24,960
And then here we should have arg min.

338
00:20:26,220 --> 00:20:27,150
There we go.

339
00:20:27,150 --> 00:20:29,700
You have one zero for two, so that's fine.

340
00:20:30,030 --> 00:20:34,080
The next method we'll look at will be this equal method.

341
00:20:34,590 --> 00:20:42,270
Essentially what this operation does is it compares each and every element based on its position.

342
00:20:42,270 --> 00:20:46,560
And then um returns um true or false.

343
00:20:46,560 --> 00:20:54,930
So looking at this example here, you see that when we compare two four that's this 1D um tensor with

344
00:20:54,930 --> 00:20:59,760
this um tensor two, we first of all start by broadcasting.

345
00:20:59,760 --> 00:21:02,370
So we would have two four compared with two two.

346
00:21:02,370 --> 00:21:06,990
And then since two is the same as two like um let's get back to our drawing board.

347
00:21:06,990 --> 00:21:11,520
Since we're comparing two four with two two.

348
00:21:11,520 --> 00:21:14,460
And since two is the same as two, we would have.

349
00:21:14,460 --> 00:21:15,150
True.

350
00:21:15,270 --> 00:21:18,360
But since four is different from two, we would have false.

351
00:21:18,360 --> 00:21:20,880
So we would have an output, which is true.

352
00:21:20,880 --> 00:21:24,570
And then uh, right here which, which is true and then false.

353
00:21:24,570 --> 00:21:27,450
Now when they are exactly the same we have true true.

354
00:21:27,450 --> 00:21:30,420
The next will be the power method.

355
00:21:30,420 --> 00:21:31,980
Let's check our power.

356
00:21:32,100 --> 00:21:33,930
Um, it should be this here.

357
00:21:33,960 --> 00:21:36,810
Now feel free to check out the others we're just going through.

358
00:21:36,810 --> 00:21:39,900
So you have an idea of of the important methods.

359
00:21:39,900 --> 00:21:45,480
Well, this power does is it, um, computes the power of one value to another.

360
00:21:45,480 --> 00:21:47,550
So it's again element wise.

361
00:21:47,550 --> 00:21:50,070
So if you have this example you see here you have two.

362
00:21:50,070 --> 00:21:51,120
Let's copy this.

363
00:21:51,120 --> 00:21:53,550
And um let's take this from here.

364
00:21:53,970 --> 00:21:55,230
There we go.

365
00:21:55,590 --> 00:21:56,880
Let's get back here.

366
00:21:56,880 --> 00:21:59,790
Paste out that we have x y.

367
00:21:59,790 --> 00:22:03,900
And then let's reduce this so that it could uh might be much clearer.

368
00:22:03,900 --> 00:22:04,740
So that's fine.

369
00:22:04,740 --> 00:22:05,190
Okay.

370
00:22:05,190 --> 00:22:07,440
So now we have two to the power of zero.

371
00:22:07,440 --> 00:22:08,370
Let's run this.

372
00:22:08,460 --> 00:22:14,100
We would have two to the power of zero which is one, two to the power of one, which is, um, two,

373
00:22:14,100 --> 00:22:17,250
three to the power of two, which is nine, three to the power of three, which is 27.

374
00:22:17,250 --> 00:22:18,480
So you see, that's it.

375
00:22:18,480 --> 00:22:21,540
So that's essentially what this power method does.

376
00:22:21,540 --> 00:22:24,030
Now the next will be the reduce methods.

377
00:22:24,030 --> 00:22:28,380
So here we have reduce or reduce any write up to reduce variance.

378
00:22:28,380 --> 00:22:35,070
Now let's just pick out this reduce max which is um one of the most commonly used um among this reduce

379
00:22:35,070 --> 00:22:35,760
methods.

380
00:22:36,270 --> 00:22:41,850
Um here what we have is it computes the maximum of elements across dimensions of a tensor.

381
00:22:41,850 --> 00:22:46,110
So let's let's just copy this and then go ahead and test it out.

382
00:22:46,110 --> 00:22:51,300
So here we have an example like this 15124.

383
00:22:51,300 --> 00:22:53,460
So let's first of all paste out the code.

384
00:22:53,460 --> 00:22:54,180
We copy it.

385
00:22:54,180 --> 00:23:03,060
And then we have as input tensor input um input tensor our tensor flow constant.

386
00:23:03,060 --> 00:23:08,130
And then we have 5124 okay.

387
00:23:08,130 --> 00:23:17,370
So what this does essentially is it simply sums up all the or rather it simply looks for the max of

388
00:23:17,370 --> 00:23:19,080
all these elements.

389
00:23:19,110 --> 00:23:20,700
Now the max here is five.

390
00:23:20,700 --> 00:23:22,140
So we have five.

391
00:23:22,140 --> 00:23:28,170
Now if we change this to sum if we change it to sum, you will find that it's going to reduce all this

392
00:23:28,170 --> 00:23:29,490
into the sum.

393
00:23:29,490 --> 00:23:34,080
So five plus one is um six six plus 288 plus 412.

394
00:23:34,230 --> 00:23:35,250
Let's run that.

395
00:23:35,250 --> 00:23:37,410
You see we have the value of 12.

396
00:23:37,410 --> 00:23:43,200
Now um let's specify like here the axis is set to none and keep dims is set to false.

397
00:23:43,230 --> 00:23:44,310
We take out name.

398
00:23:45,420 --> 00:23:48,780
Now let's say we set this keep dims to true.

399
00:23:49,710 --> 00:23:51,540
Well let's print this out separately.

400
00:23:51,540 --> 00:23:57,750
So let's print um let's print this out and then let's print.

401
00:23:57,750 --> 00:24:04,980
Well let's just copy that piece out here we have keep dream or keep dims set to false.

402
00:24:04,980 --> 00:24:06,390
So we run that.

403
00:24:06,390 --> 00:24:07,290
There we go.

404
00:24:07,290 --> 00:24:11,580
You will notice that we have two um different outputs here.

405
00:24:11,580 --> 00:24:14,160
We have still this tensor with value 12.

406
00:24:14,160 --> 00:24:15,510
And here we have the value 12.

407
00:24:15,510 --> 00:24:18,540
But with the difference that this is a 1D array.

408
00:24:18,540 --> 00:24:21,450
Whereas here we have um A0D array.

409
00:24:21,450 --> 00:24:25,110
Now this the or simple um scalar.

410
00:24:25,110 --> 00:24:31,950
Now the reason why we are having this for the first output is because we've decided to keep the dimensions.

411
00:24:31,950 --> 00:24:37,440
So um, we are going to carry out the reduce sum that's we're going to sum up all these elements, but

412
00:24:37,440 --> 00:24:41,400
we are going to maintain the original dimensions which here in this case was 1D.

413
00:24:41,400 --> 00:24:45,330
So that's why we have this 1D array, uh this 1D tensor.

414
00:24:45,330 --> 00:24:49,380
And then here we are not we don't necessarily or we don't keep these dimensions.

415
00:24:49,380 --> 00:24:51,330
And so that's why we have this output scalar.

416
00:24:51,330 --> 00:24:54,090
Now if we have um 2D.

417
00:24:54,090 --> 00:24:55,500
So let's change this to 2D.

418
00:24:56,040 --> 00:24:59,340
Let's just copy out an output we had already previously.

419
00:24:59,340 --> 00:25:01,230
So let's take this one.

420
00:25:01,920 --> 00:25:02,940
There we go.

421
00:25:02,940 --> 00:25:05,850
We have that and then take this off.

422
00:25:05,850 --> 00:25:08,280
So let's say input tensor.

423
00:25:09,390 --> 00:25:10,530
Peace out.

424
00:25:12,090 --> 00:25:15,600
Um get back take this off.

425
00:25:15,720 --> 00:25:16,410
That's fine.

426
00:25:16,410 --> 00:25:19,050
So let's run this again and see what we get.

427
00:25:19,710 --> 00:25:20,190
Now.

428
00:25:20,190 --> 00:25:28,080
You see, we we we let's first of all, um, comment this part, this comment that run that again,

429
00:25:28,080 --> 00:25:30,150
we have this output of 65.

430
00:25:30,150 --> 00:25:36,390
Now if you had if you had to sum up all this, let's just take out the max since it's easy to to see

431
00:25:36,390 --> 00:25:37,650
the output clearly.

432
00:25:37,650 --> 00:25:42,540
So you see the max here, the max value we have um, of all these different values is nine.

433
00:25:42,540 --> 00:25:43,380
So that's it.

434
00:25:43,380 --> 00:25:46,590
And then if we were to take the sum, let's get back to sum.

435
00:25:47,460 --> 00:25:49,140
And you have to add all this up.

436
00:25:49,140 --> 00:25:51,420
Three plus one plus nine plus six plus five.

437
00:25:51,420 --> 00:25:54,480
All this up is going to give us 65.

438
00:25:54,510 --> 00:25:58,350
Now if we set this skip James to to true.

439
00:25:58,350 --> 00:25:59,730
Let's just take all this off.

440
00:25:59,730 --> 00:26:05,760
If we set the kingdoms to true you'll see that because we have a 2D input, we're going to we're still

441
00:26:05,760 --> 00:26:07,530
going to have a 2D output.

442
00:26:07,530 --> 00:26:09,540
So the dimensions are maintained.

443
00:26:09,540 --> 00:26:11,670
And let's get back to false.

444
00:26:11,670 --> 00:26:15,750
And then now for the axis uh, which is set to known.

445
00:26:15,750 --> 00:26:17,280
So we don't specify any axis.

446
00:26:17,280 --> 00:26:23,730
But if we had to specify this axis and set it to zero for example, then similar to what we had seen

447
00:26:23,730 --> 00:26:31,620
in previous examples like the, uh, um, Max, I mean, here again, we are going to simply go through

448
00:26:31,620 --> 00:26:36,510
each and every row at every position and then sum up the values.

449
00:26:36,510 --> 00:26:39,210
So we have three plus zero plus one plus seven.

450
00:26:39,210 --> 00:26:40,680
That's um 11.

451
00:26:40,680 --> 00:26:42,150
So that's that's it right here.

452
00:26:42,150 --> 00:26:43,050
One plus one.

453
00:26:43,050 --> 00:26:44,700
That's two 710.

454
00:26:44,700 --> 00:26:45,450
So that's it.

455
00:26:45,450 --> 00:26:46,560
And so on and so forth.

456
00:26:46,560 --> 00:26:48,540
So that's how we have all the different values.

457
00:26:48,540 --> 00:26:56,460
Now if you specify um one then we'll sum all these values um for the different columns.

458
00:26:56,460 --> 00:26:57,780
So let's run that.

459
00:26:57,780 --> 00:26:59,670
And you see we have three plus one.

460
00:26:59,670 --> 00:27:01,020
That's four plus nine.

461
00:27:01,020 --> 00:27:06,660
That's um 13 plus 11 that's 24 and so on and so forth.

462
00:27:06,660 --> 00:27:14,310
Now clearly if you just add all this up, you should see that this is um 65 here we have 20 that's 18,

463
00:27:14,310 --> 00:27:17,190
18 plus, um, 24 plus 13.

464
00:27:17,190 --> 00:27:18,270
That gives us 65.

465
00:27:18,270 --> 00:27:25,290
So here we see already that with a reduced sum we could reduce across specific axes.

466
00:27:25,290 --> 00:27:28,680
Now let's set this to true and see what we get.

467
00:27:29,010 --> 00:27:29,880
There we go.

468
00:27:29,880 --> 00:27:33,240
You see because we want to maintain or we want to keep the dimensions.

469
00:27:33,240 --> 00:27:34,410
We still have.

470
00:27:34,560 --> 00:27:38,820
Uh, we, we have the, the same outputs, but now with a different shape.

471
00:27:38,820 --> 00:27:43,020
Again, as we've said, we have different methods, um, or different reduce methods.

472
00:27:43,020 --> 00:27:50,310
We have reduce mean, reduce um prod, reduce std, reduce variance, reduce log sum exponential, reduce

473
00:27:50,310 --> 00:27:52,620
Euclidean norm, reduce any, reduce all.

474
00:27:52,620 --> 00:27:54,810
So you could feel free to check this out.

475
00:27:54,930 --> 00:27:57,660
The next method we'll be looking at will be the top key.

476
00:27:57,660 --> 00:28:07,890
So let's click here on top K um with the top k if we have an input let's say we have um a 1D input like

477
00:28:07,890 --> 00:28:08,310
here.

478
00:28:08,310 --> 00:28:10,020
You see we have this 1D input.

479
00:28:10,020 --> 00:28:11,010
Let's just copy this.

480
00:28:11,010 --> 00:28:18,540
If we have this 1D input you would find that it's going to produce the top k values just as the the

481
00:28:18,540 --> 00:28:20,220
the the method name goes.

482
00:28:20,220 --> 00:28:21,990
So let's print out from here.

483
00:28:21,990 --> 00:28:23,700
Let's print out results.

484
00:28:24,750 --> 00:28:26,070
Um the top k already.

485
00:28:26,070 --> 00:28:27,360
Clearly you see them.

486
00:28:27,360 --> 00:28:30,750
You have 9098, 99.

487
00:28:30,750 --> 00:28:31,050
All right.

488
00:28:31,050 --> 00:28:31,950
At the top three.

489
00:28:31,980 --> 00:28:33,000
The top three.

490
00:28:33,690 --> 00:28:35,790
Uh we have 98, 99, 96.

491
00:28:35,790 --> 00:28:37,140
So that makes sense.

492
00:28:37,140 --> 00:28:44,460
Now if you scroll here you will find that apart from the the top values we also have the positions.

493
00:28:44,460 --> 00:28:47,940
So 99 is found under the feet um index.

494
00:28:47,940 --> 00:28:52,140
So we have 012345.

495
00:28:52,140 --> 00:28:53,550
So that's why we have five.

496
00:28:53,550 --> 00:28:59,610
So we're not or we don't only output the top three values, we also output the top um the positions

497
00:28:59,610 --> 00:29:00,630
of the top three values.

498
00:29:00,630 --> 00:29:04,470
If we change this to top five you see we would have more values now.

499
00:29:04,470 --> 00:29:04,710
Yeah.

500
00:29:04,710 --> 00:29:07,890
Here we have 99989643.

501
00:29:07,920 --> 00:29:14,250
If we change it to top one that essentially just the the max value we will have 99.

502
00:29:14,250 --> 00:29:16,110
And obviously we will have this position.

503
00:29:16,110 --> 00:29:22,200
So that's um, essentially what um, or how we could make use of the top k um method.

504
00:29:22,230 --> 00:29:26,790
The last method we'll be looking at in this section will be the sigmoid, um, function.

505
00:29:26,790 --> 00:29:28,800
So let's check out sigmoid.

506
00:29:29,100 --> 00:29:30,330
Um there we go.

507
00:29:30,330 --> 00:29:31,170
We have sigmoid.

508
00:29:31,170 --> 00:29:35,100
So essentially this is um a very common method.

509
00:29:35,100 --> 00:29:39,270
And wish we could make use of or wish you could call very easily.

510
00:29:39,270 --> 00:29:41,820
You could actually write this um, by yourself.

511
00:29:41,820 --> 00:29:46,230
But, um, TensorFlow already has this, so you could uh you don't need to always write that.

512
00:29:46,230 --> 00:29:53,370
So essentially what the sigmoid does is it takes in an input and then um, that input is uh negated.

513
00:29:53,370 --> 00:29:54,750
So we have minus x.

514
00:29:54,750 --> 00:29:57,810
We take the exponential of that value, we add plus one.

515
00:29:57,810 --> 00:30:00,420
And then we take one divided by whatever output we have.

516
00:30:00,420 --> 00:30:06,720
So um the sigmoid takes values from negative infinity to positive infinity and then keeps them or maintains

517
00:30:06,720 --> 00:30:08,370
them in the range zero one.

518
00:30:08,370 --> 00:30:13,620
So let's get back here and just take this off.

519
00:30:14,000 --> 00:30:15,530
So let's pull this up.

520
00:30:15,530 --> 00:30:16,640
This way.

521
00:30:16,880 --> 00:30:17,630
Get back.

522
00:30:17,630 --> 00:30:20,870
Then plot out what the sigmoid function does.

523
00:30:20,870 --> 00:30:21,500
Exactly.

524
00:30:21,500 --> 00:30:26,600
So with a sigmoid function, as we're saying, we have this function which takes values of x between

525
00:30:26,600 --> 00:30:32,600
negative infinity and positive infinity, and then maintains them um, between the range zero and one.

526
00:30:32,600 --> 00:30:37,850
So it will never cross one as well as it will never cross, um, it will never go below zero.

527
00:30:37,850 --> 00:30:41,810
So x goes from negative infinity to positive infinity.

528
00:30:41,810 --> 00:30:46,370
But the output or the result always falls in the range zero negative one.

529
00:30:46,370 --> 00:30:51,440
And we have one divided by one plus e to the negative x.

530
00:30:51,470 --> 00:30:56,870
Now again we could um call on this method with a 1D array.

531
00:30:56,870 --> 00:31:02,210
So like this for example you find that when you take a zero obviously the output should be 0.5, when

532
00:31:02,300 --> 00:31:04,610
if you look carefully at the plot you find that zero.

533
00:31:04,610 --> 00:31:06,800
Our output here is 0.5.

534
00:31:06,800 --> 00:31:12,590
So this makes sense that, um, at the level of the plot, or rather at the, at the level of this,

535
00:31:12,590 --> 00:31:15,410
um, code, we have output 0.5.

536
00:31:15,410 --> 00:31:20,090
When we take one, we have 0.73 50 is one, 100 is one.

537
00:31:20,090 --> 00:31:25,100
Now you notice that as the numbers become very large, we um, converge towards one.

538
00:31:25,100 --> 00:31:25,940
So that's it.

539
00:31:26,420 --> 00:31:32,630
Um, and obviously as we as the numbers become very small, we're going to also converge towards, um,

540
00:31:32,630 --> 00:31:33,260
zero.

541
00:31:33,260 --> 00:31:36,890
So if we let's just copy this out here.

542
00:31:37,640 --> 00:31:39,410
Um, I'll get back to the code.

543
00:31:39,410 --> 00:31:40,340
Scroll up.

544
00:31:40,760 --> 00:31:41,930
There we go.

545
00:31:42,170 --> 00:31:43,190
Let's run that.

546
00:31:43,190 --> 00:31:46,820
You see we have 0.50.7311.

547
00:31:46,820 --> 00:31:48,770
Now let's take very small numbers.

548
00:31:48,770 --> 00:31:50,900
So obviously very small negative numbers.

549
00:31:50,900 --> 00:31:58,070
So we have -50 run that you see we have these numbers now converging towards zero.

550
00:31:58,070 --> 00:31:59,720
So we have very small numbers.

551
00:31:59,720 --> 00:32:08,330
Now if we take negative um five let's increase that or five e let's say e um 100.

552
00:32:08,900 --> 00:32:09,740
Run that.

553
00:32:11,050 --> 00:32:14,530
Um, out of range for double precision float.

554
00:32:14,650 --> 00:32:16,090
Let's make that smaller.

555
00:32:16,090 --> 00:32:21,580
So we just take one zero off, run that again, and you could see that we have now zero.

556
00:32:21,580 --> 00:32:28,930
So basically as we go towards very small or very large negative numbers, we converge to a zero.

557
00:32:28,930 --> 00:32:32,560
And when we go towards very large positive numbers we converge towards one.

558
00:32:32,560 --> 00:32:34,000
Exactly as we've seen in the plot.

559
00:32:34,000 --> 00:32:37,420
You see we're getting towards zero or we are approaching zero.

560
00:32:37,420 --> 00:32:41,050
And for this we are approaching one which is right here.
