1
00:00:00,110 --> 00:00:02,990
Now we have some basic knowledge on tensors.

2
00:00:03,020 --> 00:00:07,150
Let's go ahead and create them with TensorFlow.

3
00:00:07,160 --> 00:00:16,100
So first things first, we'll import TensorFlow as TF and then you should note that because we're using

4
00:00:16,100 --> 00:00:22,430
CoLab, we do not need to install TensorFlow before making use of it.

5
00:00:22,430 --> 00:00:26,720
All we need to do here is just import and we're good to go now.

6
00:00:26,720 --> 00:00:33,080
First thing we're going to do is we're going to have our tensor, which we'll call tensor zero D And

7
00:00:33,080 --> 00:00:38,000
the way we are going to create this tensor is by calling on the constant method.

8
00:00:38,000 --> 00:00:40,820
So we have tensorflow's constant method.

9
00:00:40,820 --> 00:00:45,410
And then we specify, for example, that we want this to be, let's say four.

10
00:00:45,410 --> 00:00:46,460
So that's it.

11
00:00:46,460 --> 00:00:50,990
That's how we create a zero dimensional tensor.

12
00:00:52,020 --> 00:00:57,370
You could see here from the documentation that this constant method takes in a value, takes in a data

13
00:00:57,420 --> 00:01:01,350
type, takes in a shape and a name.

14
00:01:02,280 --> 00:01:05,520
But for now, we pass in only this value right here.

15
00:01:05,520 --> 00:01:07,110
And then we could go ahead and print this.

16
00:01:07,110 --> 00:01:14,280
So let's have tensor, um, zero d run that you could see right here.

17
00:01:14,310 --> 00:01:24,300
We've had this tensor which has a value four it has no shape and it's of type int 32 With this we could

18
00:01:24,300 --> 00:01:29,850
go ahead and build out our tensor one D tensor one D.

19
00:01:29,880 --> 00:01:33,000
We have as usual, our constant method.

20
00:01:33,000 --> 00:01:36,630
But this time around, because it's one D, we're going to have a list.

21
00:01:36,990 --> 00:01:42,030
We're going to take this list we had here to zero negative three and then put in this.

22
00:01:42,030 --> 00:01:45,990
Now right here we have to zero and negative three.

23
00:01:46,020 --> 00:01:48,280
Now let's print this out.

24
00:01:48,300 --> 00:01:53,280
We have tensor one D and there we go.

25
00:01:53,280 --> 00:01:58,800
You see, we have the value, which is this one D or this list.

26
00:01:59,340 --> 00:02:01,380
We could say shape right here.

27
00:02:01,380 --> 00:02:02,920
And then the data type.

28
00:02:02,920 --> 00:02:06,880
Now let's modify this and say we have eight and let's say 90.

29
00:02:06,910 --> 00:02:09,760
Let's run this now and check out its shape.

30
00:02:09,760 --> 00:02:13,210
You see here, this is our new list or this our new tensor.

31
00:02:13,210 --> 00:02:17,380
And then you see now it's five because we have five elements in here.

32
00:02:17,860 --> 00:02:19,840
But again, this is still an integer.

33
00:02:19,840 --> 00:02:21,580
So let's add this here.

34
00:02:21,730 --> 00:02:25,030
Change this to a float and then see what we have here.

35
00:02:25,030 --> 00:02:33,340
Now, this is a float, so it's still, um, inputs, but this time around floats same shape, but the

36
00:02:33,340 --> 00:02:36,250
data type changes from int to float.

37
00:02:36,430 --> 00:02:41,170
Let's get back to integer and then we move now to the 2D tensor.

38
00:02:41,170 --> 00:02:45,130
So we've looked at 0D1D to create a 2D tensor.

39
00:02:45,160 --> 00:02:49,900
It's going to be quite as simple as we have done with the zero D and one D.

40
00:02:49,900 --> 00:02:55,450
So here we have two D and then we have a zero constant.

41
00:02:55,450 --> 00:02:59,770
And then, um, let's open up this square brackets.

42
00:02:59,770 --> 00:03:05,140
So we have the square brackets right here, open up and then we have.

43
00:03:06,080 --> 00:03:08,180
This 2D tensor we have seen already.

44
00:03:08,180 --> 00:03:10,400
So let's have this right.

45
00:03:10,430 --> 00:03:12,710
Here we have 120.

46
00:03:13,250 --> 00:03:17,840
We put a comma to move to the next row or to the next line.

47
00:03:17,840 --> 00:03:19,970
We have three, five minus one.

48
00:03:21,690 --> 00:03:27,480
Then we have one, five, six, and then we have two, three, eight.

49
00:03:27,510 --> 00:03:28,020
Okay.

50
00:03:28,020 --> 00:03:37,080
So as you could see here, we have this 1D tensors which we stack and which will form our 2D tensor.

51
00:03:37,110 --> 00:03:41,550
Now, as usual, we have our constant method which takes in this value.

52
00:03:41,550 --> 00:03:48,240
And it should also take note of the fact that we have this outside of this stacked 1D tensors.

53
00:03:48,270 --> 00:03:50,040
Now we have this.

54
00:03:50,040 --> 00:03:54,540
Let's go ahead and print out tensor 2D.

55
00:03:54,690 --> 00:03:59,250
We have tensor 2D and there we go.

56
00:03:59,250 --> 00:04:01,650
As you could see, we have our 2D tensor.

57
00:04:01,680 --> 00:04:02,550
That's it.

58
00:04:02,580 --> 00:04:06,510
We have the shape four by three, which is what we expected.

59
00:04:06,510 --> 00:04:09,150
And then the data type is Int32.

60
00:04:09,600 --> 00:04:16,860
From here we move on to the 3D tensor, which is essentially made of this 2D tensors which have been

61
00:04:16,860 --> 00:04:17,940
stacked together.

62
00:04:17,940 --> 00:04:21,940
So let's go ahead and see how to create this with tensor flow.

63
00:04:22,510 --> 00:04:25,270
We'll start by putting together those 2D tensors.

64
00:04:25,270 --> 00:04:31,000
We had 12035 minus one.

65
00:04:31,000 --> 00:04:35,290
So that's it, three, five minus one.

66
00:04:35,290 --> 00:04:39,460
And then we have all those remaining 2D tensors.

67
00:04:39,460 --> 00:04:41,190
So let's get here.

68
00:04:41,200 --> 00:04:48,340
We have tensor three, tensor three D is a constant.

69
00:04:49,150 --> 00:04:58,180
We have our square bracket here and then we simply copy this, copy this, and then paste this in here.

70
00:04:58,630 --> 00:05:02,170
Now let's print this out and see what we get.

71
00:05:02,170 --> 00:05:05,020
So here we have tensor two.

72
00:05:06,480 --> 00:05:06,810
The.

73
00:05:08,000 --> 00:05:09,770
As you could see, we get an error.

74
00:05:09,770 --> 00:05:12,710
And this comes from the fact that we omitted commas.

75
00:05:12,740 --> 00:05:20,100
Now, if you look at this, you'll see that between one, one, D and another one D to form this two

76
00:05:20,150 --> 00:05:20,420
d.

77
00:05:20,630 --> 00:05:21,560
There is a comma.

78
00:05:21,560 --> 00:05:27,940
And so this means that between this two D and this other two D, there should be a comma.

79
00:05:27,950 --> 00:05:29,670
So let's have this comma here.

80
00:05:29,690 --> 00:05:31,520
Let's have this comma.

81
00:05:31,550 --> 00:05:34,880
Let's have this comma and this comma.

82
00:05:34,910 --> 00:05:37,700
Okay, so let's run that again and see what we get.

83
00:05:38,440 --> 00:05:43,000
As you could see, we have this our 3D output of shape, four by two by three.

84
00:05:43,000 --> 00:05:47,800
And that's exactly what we expect to get data type int 32.

85
00:05:48,070 --> 00:05:53,500
Now, before we move on, we could we should note that we could also do let's, let's have this here.

86
00:05:53,500 --> 00:06:02,380
We could also do, um, tensor 3D shape to obtain this tensor shape.

87
00:06:02,380 --> 00:06:05,290
So you see that we have that right there.

88
00:06:05,320 --> 00:06:07,510
We could replace this zero.

89
00:06:08,080 --> 00:06:11,320
We could have one C that's zero.

90
00:06:11,350 --> 00:06:12,400
That's one.

91
00:06:12,670 --> 00:06:14,020
That's two.

92
00:06:15,330 --> 00:06:16,620
Um, there we go.

93
00:06:16,650 --> 00:06:16,980
Let's.

94
00:06:16,980 --> 00:06:18,240
Let's have one.

95
00:06:18,570 --> 00:06:19,710
That's one.

96
00:06:20,670 --> 00:06:21,440
Um, that's it.

97
00:06:21,450 --> 00:06:22,110
Okay.

98
00:06:22,170 --> 00:06:23,820
And also, we could also have.

99
00:06:23,850 --> 00:06:25,380
Yeah, let's say three.

100
00:06:25,410 --> 00:06:26,780
We could do nzime.

101
00:06:26,850 --> 00:06:33,060
And this gives us a value of three showing us that our tensor is a 3D tensor at this point.

102
00:06:33,090 --> 00:06:39,090
We've looked at zero D, one, D, two, D, and even the three d tensor.

103
00:06:39,120 --> 00:06:42,540
Let's go ahead and check out a 4D tensor.

104
00:06:42,540 --> 00:06:47,160
But to construct a 4D tensor, we need several 3D tensors.

105
00:06:47,160 --> 00:06:48,970
So let's have this.

106
00:06:48,990 --> 00:06:51,120
Here we have this 3D.

107
00:06:51,330 --> 00:06:52,740
Well, we saw this already.

108
00:06:52,740 --> 00:06:53,820
This is the 3D.

109
00:06:54,150 --> 00:06:57,420
And then we move to this other one right here.

110
00:06:57,450 --> 00:06:58,790
Others, two others.

111
00:06:58,800 --> 00:07:03,420
We, we have this other 3D and this other 3D.

112
00:07:03,660 --> 00:07:11,010
And then now if we stack this three 3D up, what we will obtain will be a 4D tensor.

113
00:07:11,080 --> 00:07:15,610
See, we have this one, we add this other and we have this other.

114
00:07:15,610 --> 00:07:25,000
So now we have here a four dimensional tensor which is made of three three dimensional tensors.

115
00:07:25,030 --> 00:07:29,050
Now, you should know that this could be two, this could be four, this could be whatever number.

116
00:07:29,050 --> 00:07:35,260
So if we consider only this two, then we're talking about two, three dimensional tensors.

117
00:07:35,260 --> 00:07:41,920
But what's so important to note here is the fact that once you stack several 3D tensors, you create

118
00:07:41,920 --> 00:07:43,990
a 4D tensor.

119
00:07:44,380 --> 00:07:50,620
Now, at this point, you could take it as an exercise to create your own 4D tensor so you could pause

120
00:07:50,620 --> 00:07:51,340
the video.

121
00:07:51,340 --> 00:07:56,830
But um, we are going to go ahead and show you how to create this.

122
00:07:57,430 --> 00:07:58,480
First things first.

123
00:07:58,480 --> 00:08:01,360
We're going to take up our 3D here.

124
00:08:01,390 --> 00:08:03,180
We have this 3D tensor.

125
00:08:03,190 --> 00:08:04,900
Let's just copy this.

126
00:08:05,500 --> 00:08:06,730
There we go.

127
00:08:06,730 --> 00:08:08,560
We paste this out here.

128
00:08:10,280 --> 00:08:12,320
Let's repeat that operation.

129
00:08:12,410 --> 00:08:13,610
Copy and paste again.

130
00:08:13,610 --> 00:08:15,320
But now let's modify some values.

131
00:08:15,320 --> 00:08:18,620
So let's say we have 1326.

132
00:08:18,740 --> 00:08:20,870
Let's just randomly modify this.

133
00:08:21,710 --> 00:08:26,900
23 So it's now this these are the three different from the other one, say 30.

134
00:08:26,930 --> 00:08:33,080
Okay, now let's copy this again and then paste out here.

135
00:08:33,080 --> 00:08:35,780
So we have the three 3D tensors.

136
00:08:36,200 --> 00:08:37,970
Um, let's say this is one.

137
00:08:37,970 --> 00:08:40,700
Oh, let's just add zeros.

138
00:08:40,850 --> 00:08:51,260
We have here, um, 23, um, to four and say two.

139
00:08:51,260 --> 00:09:01,040
Okay, so now we have our three 3D tensors, we have this one, we have this other one and then we have

140
00:09:01,040 --> 00:09:02,570
this other one.

141
00:09:02,720 --> 00:09:04,820
Now to create our 4D tensor.

142
00:09:04,850 --> 00:09:08,270
As usual, we call on our, our constant method.

143
00:09:08,270 --> 00:09:17,130
So we have four D um, we have the constant and as usual, we have our square brackets which will open

144
00:09:17,130 --> 00:09:17,520
up.

145
00:09:17,520 --> 00:09:26,520
And then now we just simply take this copy all this to the end, cut this from here and then paste this

146
00:09:26,520 --> 00:09:27,090
out here.

147
00:09:27,120 --> 00:09:31,380
Okay, so we see we have three of this, um, 3D tensors.

148
00:09:31,380 --> 00:09:38,400
Now, remember last time when you were separating two 3D tensors or between the 3D tensors?

149
00:09:38,400 --> 00:09:40,320
We need to have a comma.

150
00:09:40,320 --> 00:09:46,110
So here we're going to have this comma, and then here we're going to have this comma.

151
00:09:46,110 --> 00:09:48,900
And here we have comma.

152
00:09:48,930 --> 00:09:50,280
Okay, so that's it.

153
00:09:50,280 --> 00:09:54,330
So let's run this or let's print this out and then see what we get.

154
00:09:54,330 --> 00:10:01,920
So here we have print, um, tensor 4D, There we go.

155
00:10:02,340 --> 00:10:06,390
You could see from here we have our 4D tensor.

156
00:10:06,720 --> 00:10:10,080
You see it's shape three by four, by two by three.

157
00:10:10,560 --> 00:10:14,880
And this is because our 4D tensor is made of one.

158
00:10:15,120 --> 00:10:16,040
Let's take this off.

159
00:10:16,050 --> 00:10:21,090
It's made of one, two, three 3D tensors.

160
00:10:21,090 --> 00:10:23,010
So that's why we have three.

161
00:10:23,190 --> 00:10:27,750
And then for each and every one of these, we have four.

162
00:10:27,780 --> 00:10:34,290
That's one, two, three, four, 2D tensors.

163
00:10:34,290 --> 00:10:36,150
So here we have four.

164
00:10:36,150 --> 00:10:45,780
And for every 2D tensor we have one, two, that's two rows and one, two, three.

165
00:10:45,810 --> 00:10:47,640
That's three columns.

166
00:10:48,710 --> 00:10:51,380
And that's now exactly what we have here.

167
00:10:51,380 --> 00:10:53,560
So we still have the same data type.

168
00:10:53,570 --> 00:10:58,330
We have our values, which you could have here, and that's it.

169
00:10:58,340 --> 00:11:02,540
If we get back here, we'll see that we have different data types which we could use.

170
00:11:02,540 --> 00:11:15,440
So instead of just this default int, we could have TF float say 32 and you'll notice that the output

171
00:11:15,440 --> 00:11:22,850
as we have seen already, should have these decimals since we now dealing with floats.

172
00:11:23,000 --> 00:11:31,460
Now the float we have in here is of type float 32 or specifically the float 32, meaning that the precision

173
00:11:31,460 --> 00:11:32,810
value here is 32.

174
00:11:32,810 --> 00:11:40,190
Now if we reduce this, if we reduce this, you will see that you would actually have the same output.

175
00:11:40,460 --> 00:11:49,350
But the difference is that less memory is allocated for storing this tensor as compared to maybe even,

176
00:11:49,350 --> 00:11:52,200
let's say the 64 that's float 64.

177
00:11:52,440 --> 00:11:59,340
And so in certain contexts where we have the memory constraint, we would want to use the lower precision

178
00:11:59,340 --> 00:12:02,130
tensors in the documentation.

179
00:12:02,130 --> 00:12:08,850
You could have all the different data types of which are supported in TensorFlow.

180
00:12:08,850 --> 00:12:16,830
So here we have quantized data types and talking about quantization, we're going to treat this in subsequent

181
00:12:16,830 --> 00:12:21,960
sections and so don't bother for now if you don't really master this.

182
00:12:22,440 --> 00:12:33,060
Um, here we have the brain floating point here we have the boolean here, we have complex in its 128

183
00:12:33,060 --> 00:12:35,760
and 64 bit versions.

184
00:12:35,760 --> 00:12:41,700
Here we have the double, which in fact means the double precision floating point.

185
00:12:41,730 --> 00:12:46,530
Now this is double because the float 32 is a single precision.

186
00:12:46,530 --> 00:12:54,270
So here we have single the float 16 is half prediction or precision, and then the double is double

187
00:12:54,270 --> 00:12:55,020
precision.

188
00:12:55,470 --> 00:13:02,040
Here we have the ints and the different versions or the different precisions, or we have the quantized

189
00:13:02,040 --> 00:13:03,000
ints.

190
00:13:03,960 --> 00:13:09,810
We have resource, we have string, we have unsigned int.

191
00:13:10,680 --> 00:13:12,660
And then we have variant.

192
00:13:13,200 --> 00:13:18,480
Getting back to the code, if for example, here we had this float, let's just add this decimal.

193
00:13:18,480 --> 00:13:26,670
So we suppose that this is a float and then now we do int let's say in 64 we run that you will see that

194
00:13:26,670 --> 00:13:28,560
we will obtain an error.

195
00:13:28,560 --> 00:13:30,930
So let's have this here.

196
00:13:30,960 --> 00:13:31,890
What do we see?

197
00:13:31,890 --> 00:13:39,350
We told that we cannot convert this tensor to or to eager tensor of data type in 64.

198
00:13:39,360 --> 00:13:47,160
But now if we use the cast method, if we do TensorFlow cast and then here.

199
00:13:47,610 --> 00:13:49,140
All right, let's take this back.

200
00:13:49,140 --> 00:13:55,980
Let's let's have our TensorFlow or our tensor 1D and then let's take this off or let's yeah, let's

201
00:13:55,980 --> 00:13:59,340
just have this float 64.

202
00:13:59,520 --> 00:14:00,540
There we go.

203
00:14:00,540 --> 00:14:10,140
Or let's say float 32, and then let's say we define some casted tensor or cast a tensor 1D and then

204
00:14:10,240 --> 00:14:15,730
this casted tensor 1D is simply going to be the casted version of this or 1D tensor.

205
00:14:15,730 --> 00:14:24,250
So here we have tensor 1D and then we specify the data type and then we say we want this to be in 16,

206
00:14:24,250 --> 00:14:25,090
for example.

207
00:14:25,090 --> 00:14:32,680
So here we're going to print out the tensor 1D and we're also going to print out the casted tensor 1D.

208
00:14:33,730 --> 00:14:37,450
We getting this error we should have had TF DOT.

209
00:14:37,450 --> 00:14:39,670
So let's have this here.

210
00:14:39,820 --> 00:14:40,810
There we go.

211
00:14:40,810 --> 00:14:44,170
And then let's look at what we have as output.

212
00:14:44,590 --> 00:14:53,710
As you could see, thanks to the casting operation, we are able to get from this float to this integer

213
00:14:53,710 --> 00:14:54,550
tensor.

214
00:14:54,820 --> 00:15:00,940
And so this tells us that instead of coming right here and saying, for example, int 16 or let's say

215
00:15:00,940 --> 00:15:04,780
in 32, it's preferable to make use of the cast method.

216
00:15:05,230 --> 00:15:13,290
That said, let's say for example, instead of having this, that's instead of casting this into an

217
00:15:13,290 --> 00:15:15,450
integer, we want to cast this into a Boolean.

218
00:15:15,450 --> 00:15:16,950
So let's run this.

219
00:15:17,550 --> 00:15:23,910
You see here that we get all of true except for this one here, which is false.

220
00:15:23,910 --> 00:15:25,980
And that's simply because this is a zero.

221
00:15:25,980 --> 00:15:32,130
So it looks like the water casting method does is for all the values which are different from zero,

222
00:15:32,160 --> 00:15:35,760
they are true, but values equal zero, equal false.

223
00:15:36,270 --> 00:15:38,640
We could also go ahead and create our own Boolean.

224
00:15:38,640 --> 00:15:48,120
So let's say we have tensor tensor bool, let's call this tensor bool and then we have all this list

225
00:15:48,120 --> 00:15:49,260
made of this tensor.

226
00:15:49,260 --> 00:15:54,120
So we could have true, true false, true, true, false.

227
00:15:54,120 --> 00:15:58,080
Okay, so let's print out tensor board and see what we get.

228
00:15:59,040 --> 00:16:04,900
As you could see here, we have our output tensor of shape three and here is values.

229
00:16:04,910 --> 00:16:07,350
You see the data type bool right here.

230
00:16:07,380 --> 00:16:10,950
Now another data type, which you could look at is the string.

231
00:16:10,950 --> 00:16:13,570
So let's, let's say we want to have tensor string.

232
00:16:14,080 --> 00:16:16,720
Um, there we go.

233
00:16:16,720 --> 00:16:19,780
Let's say we want to have um, hello world.

234
00:16:19,810 --> 00:16:21,400
Hello world.

235
00:16:22,450 --> 00:16:23,860
Let's print this out.

236
00:16:23,890 --> 00:16:26,470
Tensor string.

237
00:16:27,160 --> 00:16:28,090
There we go.

238
00:16:28,090 --> 00:16:29,290
We have our tensor.

239
00:16:29,290 --> 00:16:33,520
We could also put this in a list because right now this zero dimensional tensor.

240
00:16:33,520 --> 00:16:39,880
So let's put this in a list and, uh, hello, world.

241
00:16:39,880 --> 00:16:40,690
Hi.

242
00:16:40,690 --> 00:16:42,610
And we'll close that.

243
00:16:43,510 --> 00:16:48,970
And now we have this 1D tensor of Shape two, which is a string from here.

244
00:16:49,000 --> 00:16:55,690
We would also look at how to create or how to convert a numpy array into a tensor.

245
00:16:55,690 --> 00:16:59,260
So let's call this, um, NP array.

246
00:16:59,290 --> 00:17:02,230
First of all, we'll start by importing numpy as NP.

247
00:17:02,440 --> 00:17:04,150
We could just do that right here.

248
00:17:04,150 --> 00:17:06,190
Import numpy as np.

249
00:17:06,550 --> 00:17:07,630
There we go.

250
00:17:07,630 --> 00:17:17,850
And then we have um np array and let's say we have NP array and then let's take in this here, let's

251
00:17:17,850 --> 00:17:20,220
say one, two, 3 or 1 two, four.

252
00:17:20,250 --> 00:17:21,030
There we go.

253
00:17:21,390 --> 00:17:22,230
Print this out.

254
00:17:22,230 --> 00:17:24,780
We have NP array right here.

255
00:17:25,530 --> 00:17:30,690
Now we could make use of this TensorFlow convert to tensor method.

256
00:17:30,690 --> 00:17:43,080
So let's say we have here converted converted tensor and we have um, convert to tensor which essentially

257
00:17:43,080 --> 00:17:45,930
takes in a numpy array.

258
00:17:45,960 --> 00:17:51,990
Now let's have this and then print out the converted um, tensor.

259
00:17:52,620 --> 00:18:00,150
With that, getting back to the documentation, we could look at a couple of other methods, like the

260
00:18:00,150 --> 00:18:00,990
AI method.

261
00:18:00,990 --> 00:18:03,870
Here we have this AI method right here.

262
00:18:03,900 --> 00:18:09,810
As usual, we have the well described method in the documentation.

263
00:18:09,910 --> 00:18:16,390
Station, which comes with this short phrase explaining how it works.

264
00:18:16,410 --> 00:18:23,250
It comes with this different arguments and also even some examples.

265
00:18:23,250 --> 00:18:31,650
So getting back here, we told that this method permits us construct an identity matrix or a batch of

266
00:18:31,650 --> 00:18:32,550
matrices.

267
00:18:32,970 --> 00:18:34,920
So now we have this definition.

268
00:18:34,920 --> 00:18:41,040
We could simply copy this out and then get back to the code right here, paste this out, and let's

269
00:18:41,040 --> 00:18:44,760
say we call this, um, AI tensor.

270
00:18:45,150 --> 00:18:46,320
AI tensor.

271
00:18:46,320 --> 00:18:55,710
And for now we have this number of columns which is known the batch shape known data type float 32 name

272
00:18:55,710 --> 00:18:56,130
known.

273
00:18:56,130 --> 00:18:59,160
Now let's say we want to have three rows.

274
00:18:59,160 --> 00:19:03,120
So we have number of rows which is equal three.

275
00:19:03,150 --> 00:19:06,450
Now in this case, uh, we'll print this out.

276
00:19:06,450 --> 00:19:08,250
So we see the kind of output we get here.

277
00:19:08,250 --> 00:19:12,820
We have AI tensor here and there we go.

278
00:19:12,820 --> 00:19:20,500
As you could see, we have this identity matrix where all the values of the matrix are zero except for

279
00:19:20,500 --> 00:19:22,390
those of the leading diagonal.

280
00:19:22,390 --> 00:19:26,380
Let's show clearly this leading diagonal right here.

281
00:19:26,380 --> 00:19:29,770
Here we have our matrix, which is this.

282
00:19:29,770 --> 00:19:35,290
And then we have this element of the leading diagonal, which is equal one.

283
00:19:35,290 --> 00:19:43,090
Now, you should note that you could you could say, for example, um, let's say three times this and

284
00:19:43,090 --> 00:19:47,890
you should have all the elements of the leading diagonal to be equal to three and the others zero.

285
00:19:47,890 --> 00:19:50,740
So in this case, we now have something like this.

286
00:19:50,740 --> 00:19:54,060
So you see all these three while the rest are zero.

287
00:19:54,070 --> 00:19:55,810
Now let's get back.

288
00:19:55,810 --> 00:20:01,870
Let's take this off Here we have our AI tensor and then we see that we could specify the number of columns

289
00:20:01,870 --> 00:20:06,040
now here, uh, or previously where this was set to none.

290
00:20:06,040 --> 00:20:07,420
We had a square matrix.

291
00:20:07,420 --> 00:20:10,300
That is when you define the number of rows to be three.

292
00:20:10,330 --> 00:20:13,510
The number of columns automatically takes up the value of three.

293
00:20:13,510 --> 00:20:15,730
So we have a three by three matrix.

294
00:20:15,730 --> 00:20:18,670
And obviously the type here is float32.

295
00:20:18,730 --> 00:20:26,620
We could modify this and say, for example, 16 on that, let's try out bold after this.

296
00:20:27,760 --> 00:20:28,630
There we go.

297
00:20:28,630 --> 00:20:29,770
We have float 16.

298
00:20:29,770 --> 00:20:30,670
Let's try out bold.

299
00:20:32,530 --> 00:20:34,030
You see everywhere is false.

300
00:20:34,030 --> 00:20:34,480
False.

301
00:20:34,480 --> 00:20:35,170
False.

302
00:20:35,170 --> 00:20:36,460
False, false, false.

303
00:20:36,490 --> 00:20:38,920
Except for the leading diagonal, which has true.

304
00:20:39,640 --> 00:20:44,920
Now getting back, let's say here we have five and then now number of columns.

305
00:20:44,920 --> 00:20:46,240
Let's say this to three.

306
00:20:47,560 --> 00:20:49,720
You see right here, this is the output we get.

307
00:20:49,750 --> 00:20:54,610
Now it's it acts like we have a five by five matrix.

308
00:20:54,610 --> 00:20:58,720
So we suppose we add a five by five matrix where this will be zero zero.

309
00:20:58,750 --> 00:21:00,940
This would have been zero zero.

310
00:21:00,970 --> 00:21:03,400
This would have been zero zero.

311
00:21:03,430 --> 00:21:08,470
This would have been one if this was five by five zero and then here zero one.

312
00:21:08,470 --> 00:21:13,960
So this is what we would have had if we did not if we let this to to be known.

313
00:21:13,960 --> 00:21:16,720
That is number of rows, equal number of columns.

314
00:21:16,720 --> 00:21:21,280
But now that we've set number of columns to be three, this part has been cut off.

315
00:21:21,280 --> 00:21:23,050
And so this is what we're left with.

316
00:21:23,080 --> 00:21:30,640
Now, with that said, let's go ahead and take this back to Known and then let's set a batch shape.

317
00:21:30,640 --> 00:21:32,480
So let's say this is three.

318
00:21:33,230 --> 00:21:34,430
I'll run that.

319
00:21:35,420 --> 00:21:39,770
As you could see, because we set this batch shape to be three.

320
00:21:40,230 --> 00:21:45,980
Um, here we have this output which is three by five by five.

321
00:21:45,980 --> 00:21:47,780
Well, let's, let's change this to two.

322
00:21:47,810 --> 00:21:55,490
So you could see that this actually is responsible for deciding on what number of batches we have right

323
00:21:55,490 --> 00:21:55,880
here.

324
00:21:55,880 --> 00:21:58,420
So here we have two by five by five.

325
00:21:58,430 --> 00:22:06,350
So essentially saying that you want to have this batch shape to be two like this means you want to five

326
00:22:06,650 --> 00:22:17,060
by five matrices, which are identity matrices, that is, uh, which have their values all zeros except

327
00:22:17,060 --> 00:22:20,480
for those of the leading diagonal which are equal one.

328
00:22:20,990 --> 00:22:29,720
And so we see how we could create this 3D matrix or this 3D tensor from the AI method.

329
00:22:29,750 --> 00:22:36,020
Now, we could go ahead and say for example, we want four year, let's run this and see what we get.

330
00:22:36,050 --> 00:22:40,430
We should get two by four, two by four by five by five.

331
00:22:40,520 --> 00:22:43,940
So here we have two by four, by five by five.

332
00:22:44,570 --> 00:22:46,310
And that's it for the AI method.

333
00:22:46,310 --> 00:22:49,520
We move on to the next method, the field method.

334
00:22:49,790 --> 00:22:57,080
Here we have a method as defined here in the documentation which creates a tensor field with a scalar

335
00:22:57,080 --> 00:22:57,740
value.

336
00:22:57,740 --> 00:23:02,330
So here we have this field method which we're going to copy, but before testing out the code, you

337
00:23:02,330 --> 00:23:11,630
could see here from this example that with this field method we have this tensor which takes which has

338
00:23:11,630 --> 00:23:17,030
shape two by three and which has value nine on all different positions.

339
00:23:17,030 --> 00:23:20,240
So let's get back here, paste this out.

340
00:23:20,240 --> 00:23:27,650
Let's call this field tensor and let's say this dimensions.

341
00:23:27,650 --> 00:23:33,980
Let's say we have three by four, and then let's say we want to have the value on, let's say five.

342
00:23:33,980 --> 00:23:37,040
Okay, so let's print this out and see what we get.

343
00:23:37,070 --> 00:23:39,950
Field tensor.

344
00:23:41,240 --> 00:23:42,180
And there we go.

345
00:23:42,200 --> 00:23:43,250
That's the output we get.

346
00:23:43,280 --> 00:23:45,530
Now let's have this one, for example.

347
00:23:45,620 --> 00:23:46,490
Run that.

348
00:23:48,030 --> 00:23:54,900
So we were able to create this 3D tensor where all the values are, all the elements in each position

349
00:23:54,900 --> 00:23:56,160
takes the value.

350
00:23:56,190 --> 00:23:56,850
Five.

351
00:23:56,880 --> 00:24:02,100
From here we go on to the Wands method and it should be noted that this one's method is quite similar

352
00:24:02,100 --> 00:24:07,140
to the field method in the sense that this creates a tensor just like with the field method.

353
00:24:07,140 --> 00:24:11,520
But the only difference is that here all the elements are set to one.

354
00:24:11,520 --> 00:24:17,490
So you notice that here in this definition we do not have this value argument right here.

355
00:24:17,490 --> 00:24:23,070
We had a value which we pass, but with the wands there is no value because the value by default is

356
00:24:23,070 --> 00:24:23,490
one.

357
00:24:23,490 --> 00:24:27,800
So let's have this here and then paste.

358
00:24:27,820 --> 00:24:28,620
All right, here.

359
00:24:28,660 --> 00:24:32,880
See, we have this ones, so we'll call this once tensor.

360
00:24:34,020 --> 00:24:34,860
There we go.

361
00:24:34,860 --> 00:24:40,740
We specify a shape, let's say five by three, and then we print that out.

362
00:24:40,740 --> 00:24:43,500
So here we have once tensor.

363
00:24:45,610 --> 00:24:46,330
And there we go.

364
00:24:46,330 --> 00:24:54,430
We have this output matrix which is made of five rows one, two, three, four, five and three columns.

365
00:24:54,430 --> 00:24:56,410
One, two, three.

366
00:24:57,610 --> 00:25:01,630
Where all the elements of this tensor take up the value one.

367
00:25:01,660 --> 00:25:06,970
Now, you could obviously do this to have or to obtain a 3D tensor.

368
00:25:08,020 --> 00:25:10,160
So that's the output we get to see.

369
00:25:10,690 --> 00:25:11,470
Five by three.

370
00:25:11,470 --> 00:25:12,160
By two.

371
00:25:13,990 --> 00:25:16,300
From here, we'll look at the ones like.

372
00:25:17,400 --> 00:25:25,800
And what this one does is it creates a tensor of all ones that has the same shape as the input.

373
00:25:26,510 --> 00:25:34,400
So what this means is if you have an input like this one, let's say we have um, 12, let's not make

374
00:25:34,400 --> 00:25:43,670
that 112 one three and then 572 this actually a two by three matrix.

375
00:25:43,670 --> 00:25:44,600
Let's change this.

376
00:25:44,600 --> 00:25:47,120
So you see that this is two.

377
00:25:47,240 --> 00:25:48,830
So we have the shape.

378
00:25:48,830 --> 00:25:51,680
The shape is, um, two by three.

379
00:25:51,680 --> 00:25:53,600
So its shape is two by three.

380
00:25:53,810 --> 00:26:02,420
Now if this is the input here, if this is the input into our once like method, what will get us output

381
00:26:02,450 --> 00:26:10,460
will be um, a matrix or tensor with this same shape that is with shape two by three.

382
00:26:10,460 --> 00:26:15,950
So our output is going to be having a shape two by three, meaning that we're going to have um, two

383
00:26:15,950 --> 00:26:20,150
rows and then one, two, three columns.

384
00:26:20,150 --> 00:26:27,450
But the output or rather the values we're going to insert here will be all ones.

385
00:26:27,450 --> 00:26:33,660
So now we're going to have 111111.

386
00:26:33,660 --> 00:26:42,750
So hence the name ones like, so this like is actually for the shape of this.

387
00:26:42,750 --> 00:26:46,800
So you imitating the input with respect to its shape.

388
00:26:47,490 --> 00:26:52,980
Now getting back here you see we had this field tensor which is a one by three by four tensor.

389
00:26:52,980 --> 00:26:56,820
So let's, um, let's have this right here.

390
00:26:56,850 --> 00:27:02,160
Let's say we want to have, uh, one like Tensor.

391
00:27:02,580 --> 00:27:04,110
There we go.

392
00:27:04,140 --> 00:27:10,800
TF one like, and then we have field tensor field tensor.

393
00:27:10,830 --> 00:27:11,580
There we go.

394
00:27:11,610 --> 00:27:16,230
Okay, so let's print out this one's like tensor.

395
00:27:17,160 --> 00:27:21,000
Now before printing, let's try to obtain the output.

396
00:27:21,000 --> 00:27:23,190
So here we know that this is field tensor.

397
00:27:23,220 --> 00:27:24,960
The shape is one by three by four.

398
00:27:24,960 --> 00:27:30,120
So it means that we should have an output of shape one by three by four where all these values are ones.

399
00:27:30,120 --> 00:27:34,050
So let's run that and make sure that that's the output we have.

400
00:27:36,280 --> 00:27:37,230
There we go.

401
00:27:37,270 --> 00:27:38,710
Says one by three by four.

402
00:27:38,710 --> 00:27:41,050
And we have all ones.

403
00:27:41,920 --> 00:27:44,010
From here we move to the Zeros method.

404
00:27:44,020 --> 00:27:46,690
So it's quite similar to the ones here.

405
00:27:47,200 --> 00:27:53,230
Just like with the ones we have all elements set to a given value with the ones, all the elements we

406
00:27:53,230 --> 00:27:55,060
set to one with the zeros.

407
00:27:55,090 --> 00:27:56,800
All elements are set to zero.

408
00:27:56,800 --> 00:27:58,540
So that's essentially it.

409
00:27:58,570 --> 00:28:02,110
Now let's just modify the code a little right here.

410
00:28:02,110 --> 00:28:04,480
So this was once tensor.

411
00:28:04,930 --> 00:28:08,020
Um, let's change the shape this three by two.

412
00:28:08,020 --> 00:28:16,990
And then instead of once here, let's say zero here we have zeros and let's call this well, let's say

413
00:28:16,990 --> 00:28:21,670
this is let's just copy this out and put out separately.

414
00:28:21,670 --> 00:28:31,480
So here we have this, we paste that out here, we have zeros and here we have zeros.

415
00:28:31,510 --> 00:28:32,410
Fine.

416
00:28:32,710 --> 00:28:35,840
And here we have zeros.

417
00:28:35,840 --> 00:28:37,520
Okay, so let's run that.

418
00:28:38,060 --> 00:28:39,980
And there we go.

419
00:28:39,980 --> 00:28:41,450
We should have this here.

420
00:28:41,450 --> 00:28:44,150
So we see three by two, three rows, two columns.

421
00:28:44,150 --> 00:28:44,930
That's fine.

422
00:28:44,930 --> 00:28:46,790
And all values are zeros.

423
00:28:46,790 --> 00:28:49,490
If we were, then you have all values ones.

424
00:28:49,490 --> 00:28:54,650
And for the ones or the zeros like is similar to the ones like.

425
00:28:54,650 --> 00:28:57,170
So you could take that as a simple exercise.

426
00:28:57,260 --> 00:28:58,550
We then move forward.

427
00:28:58,550 --> 00:29:05,210
We have this shape method right here where we told that this returns a tensor take note of that.

428
00:29:05,210 --> 00:29:10,070
It returns a tensor containing the shape of the input tensor.

429
00:29:10,070 --> 00:29:19,310
So, um, as we had seen before, we could obtain the shape of a tensor by simply, um, making use

430
00:29:19,310 --> 00:29:22,160
of that tensor name dot shape.

431
00:29:22,160 --> 00:29:30,320
Now, if we want to have an output like in our case now we want to have this output, um, tensor which

432
00:29:30,320 --> 00:29:34,070
contains the shape of our tensor.

433
00:29:34,880 --> 00:29:39,920
Then we could make use of this shape method from tensor flow.

434
00:29:39,920 --> 00:29:45,140
So you see here we have the same four by two by three, but this is now another list.

435
00:29:45,470 --> 00:29:49,190
Um, and then we have its shape and we also have its data type.

436
00:29:49,190 --> 00:29:55,790
Obviously it's made of integers, so we shouldn't expect to have a float data type right here.

437
00:29:56,510 --> 00:30:02,300
Another method which we could make use of is a rank method which simply returns the rank of a tensor.

438
00:30:02,300 --> 00:30:05,870
So it takes an input and then returns its rank.

439
00:30:05,870 --> 00:30:12,380
If you have a simple example right here where we have this three d tensor T, and then when you call

440
00:30:12,380 --> 00:30:15,770
on the rank method, you see that we obtain the output, which is three.

441
00:30:15,800 --> 00:30:19,340
So let's, um, put that out here.

442
00:30:19,370 --> 00:30:22,460
Let's just paste it out here and test that quickly.

443
00:30:23,150 --> 00:30:24,080
There we go.

444
00:30:24,080 --> 00:30:31,430
As you could see, because the output is a zero dimensional tensor, the shape, it actually has no

445
00:30:31,430 --> 00:30:34,250
shape, but you could see its value right here.

446
00:30:34,280 --> 00:30:35,150
That's three.

447
00:30:35,180 --> 00:30:44,240
Now, if we take out this s and take out this and then take out this other part here.

448
00:30:44,390 --> 00:30:45,680
There we go.

449
00:30:45,680 --> 00:30:46,790
We run this again.

450
00:30:46,790 --> 00:30:50,270
We should have a rank of two this time around.

451
00:30:50,870 --> 00:30:51,650
That's fine.

452
00:30:51,650 --> 00:30:52,310
It's here.

453
00:30:52,310 --> 00:30:53,360
The rank is two.

454
00:30:54,170 --> 00:30:59,870
We now move to the size here, the size method, which returns the size of a tensor.

455
00:30:59,870 --> 00:31:05,360
So you put in an input in the size method and it gives you the size of the tensor.

456
00:31:05,360 --> 00:31:08,540
We have as usual on the example here, which we could copy.

457
00:31:09,020 --> 00:31:16,550
But before running that, we could read this, um, note here where we told this returns A0D tensor

458
00:31:16,580 --> 00:31:21,830
representing the number of elements in the input of type output type.

459
00:31:21,830 --> 00:31:25,250
This is the output type here, which by default is Int32.

460
00:31:25,250 --> 00:31:32,210
So let's get back here and paste this out and check out the size.

461
00:31:33,140 --> 00:31:39,560
As you could see here, we have this size of 12 and that's because we have 12 different positions or

462
00:31:39,560 --> 00:31:42,350
12 different elements in our tensor.

463
00:31:42,350 --> 00:31:44,990
Now let's take this off again.

464
00:31:45,020 --> 00:31:46,310
Take this off.

465
00:31:46,790 --> 00:31:48,830
Um, take this off.

466
00:31:48,830 --> 00:31:49,760
There we go.

467
00:31:49,760 --> 00:31:50,660
Let's run that.

468
00:31:50,660 --> 00:31:52,130
We should have six.

469
00:31:52,460 --> 00:31:54,080
So that's it.

470
00:31:54,080 --> 00:31:55,400
You see, we have six.

471
00:31:55,400 --> 00:32:02,990
And here we could also specify this D type, um, let's say float.

472
00:32:03,020 --> 00:32:04,070
Um, 32.

473
00:32:04,880 --> 00:32:06,620
We get an error here.

474
00:32:06,860 --> 00:32:09,800
Uh, got an unexpected keyword argument D type.

475
00:32:09,800 --> 00:32:13,700
Now, getting back here, we see this is actually our type, not D type.

476
00:32:13,700 --> 00:32:19,580
So let's get back here and then we have, um, out type.

477
00:32:19,580 --> 00:32:22,790
So we have out type.

478
00:32:22,790 --> 00:32:23,720
There we go.

479
00:32:24,740 --> 00:32:25,760
Run that.

480
00:32:26,030 --> 00:32:31,250
And as you could see right now, we have a float instead of an int.

481
00:32:31,820 --> 00:32:35,480
The next step will take is creating our own.

482
00:32:35,630 --> 00:32:37,310
Random tensors.

483
00:32:37,580 --> 00:32:42,170
And that is essentially creating tensors which take up random values.

484
00:32:42,710 --> 00:32:50,540
Now, in the case of TensorFlow, random, normal, our output values are going to be from or are going

485
00:32:50,540 --> 00:32:53,870
to be drawn from a normal distribution.

486
00:32:54,320 --> 00:32:59,030
And we are going to explain, at least at a high level, what this really means.

487
00:32:59,060 --> 00:33:06,470
For now, let's just copy this out and get back to the code and run this and see what we get.

488
00:33:06,620 --> 00:33:11,030
So right here, let's say we have random tensor.

489
00:33:11,570 --> 00:33:12,410
There we go.

490
00:33:12,440 --> 00:33:14,060
We need to specify the shape.

491
00:33:14,060 --> 00:33:19,160
So we'll say let's take let's make a matrix a 2D tensor.

492
00:33:19,160 --> 00:33:20,570
So let's say is three by two.

493
00:33:20,600 --> 00:33:26,690
Now you see we have this mean value, standard deviation values which are being given right here by

494
00:33:26,690 --> 00:33:27,170
default.

495
00:33:27,170 --> 00:33:32,190
And we're going to look at what this actually means shortly.

496
00:33:32,210 --> 00:33:34,310
The data type is two.

497
00:33:34,350 --> 00:33:36,290
See, this is known name known.

498
00:33:36,300 --> 00:33:39,450
Now let's run this or let's print this out and see what we get.

499
00:33:39,450 --> 00:33:43,620
So here we have random tensor and there we go.

500
00:33:44,040 --> 00:33:48,210
As you can see, we have this set of values which are all negatives.

501
00:33:48,210 --> 00:33:51,270
And if you notice, they are very close to zero.

502
00:33:51,270 --> 00:34:04,680
So here we have practically negative one about negative two, -0.3, very small number and -0.5 -0.87.

503
00:34:04,680 --> 00:34:06,920
So these are numbers very close to seven.

504
00:34:06,930 --> 00:34:08,160
Let's run this again.

505
00:34:08,160 --> 00:34:15,380
So you see that we're able to randomly generate a matrix with this shape, with random values.

506
00:34:15,390 --> 00:34:17,610
You see that it picks up different numbers.

507
00:34:17,640 --> 00:34:18,150
This time around.

508
00:34:18,150 --> 00:34:20,280
We have a mixture of positive and negative numbers.

509
00:34:20,280 --> 00:34:24,840
But again, this numbers are very close to zero.

510
00:34:25,950 --> 00:34:33,090
Now, what if we modify this mean so we modify this, mean we'll run this again, let's see what we

511
00:34:33,090 --> 00:34:33,750
obtain.

512
00:34:33,780 --> 00:34:39,900
You see that we have this numbers now which are instead close to 100.

513
00:34:39,900 --> 00:34:49,410
And so what this tells us is that we could make use of this mean and the standard deviation to decide

514
00:34:49,410 --> 00:34:53,910
on the kinds of random values we want to have here.

515
00:34:54,470 --> 00:35:01,880
Now to better understand what is going on, let's consider this figure from this probability playground

516
00:35:01,880 --> 00:35:05,900
by Adam Cunningham from the University of Buffalo.

517
00:35:06,350 --> 00:35:15,920
As you had noticed in the code when we did TensorFlow random normal and the mean when we specify the

518
00:35:15,920 --> 00:35:18,630
mean here the mean is this mu you have here.

519
00:35:18,650 --> 00:35:25,520
When we specify the mean to be equal to zero, most of the values we had were surrounding zero.

520
00:35:26,940 --> 00:35:35,910
And when we set this machine to 100, when we set it to 100, most of the values were surrounding 100.

521
00:35:36,570 --> 00:35:40,840
Now, this curve you have here actually explains why.

522
00:35:40,860 --> 00:35:45,090
So you have this curve right here, which is bell shaped.

523
00:35:45,660 --> 00:35:54,000
And the idea here is that it permits us randomly pick values around the mean.

524
00:35:54,000 --> 00:35:55,610
That's around zero.

525
00:35:55,620 --> 00:36:03,530
So that's why you notice that at zero, we have the highest probability score here.

526
00:36:03,540 --> 00:36:05,390
Our probability score is F of X.

527
00:36:05,400 --> 00:36:14,910
So, um, for values around or values surrounding zero, that's this value surrounding zero.

528
00:36:16,100 --> 00:36:20,360
There is much higher probability or chance.

529
00:36:21,800 --> 00:36:27,440
Of them been picked as compared to values far away from zero.

530
00:36:27,440 --> 00:36:29,660
So let's pick out these two values.

531
00:36:29,660 --> 00:36:39,170
Let's say we have, um, let's say we want to pick out the two values 0.5, let's say 0.5, and we want

532
00:36:39,170 --> 00:36:40,940
to pick out negative five.

533
00:36:41,210 --> 00:36:46,760
You'll see from here that the probability of of us having negative five is practically zero.

534
00:36:46,790 --> 00:36:47,900
That's almost zero.

535
00:36:47,900 --> 00:36:53,090
But the probability of us having 0.5, as you could see from here, if you taking this middle, the

536
00:36:53,090 --> 00:36:59,060
probability of us having 0.5 is about 0.35.

537
00:37:00,740 --> 00:37:07,310
Now, if we change this value and take 100 as we did with the code, let's take a hundred.

538
00:37:07,670 --> 00:37:11,570
We have that, um, 100.

539
00:37:13,160 --> 00:37:17,720
Well, it looks like they've fixed this to six, so we cannot go above this.

540
00:37:17,930 --> 00:37:19,650
We could play around this like this.

541
00:37:19,680 --> 00:37:21,180
So you go from -6 to 6.

542
00:37:21,180 --> 00:37:22,770
Okay, let's say the mean is six.

543
00:37:22,770 --> 00:37:24,360
So we have the mean of six.

544
00:37:24,360 --> 00:37:31,110
One thing you can notice is that now this, um, 0.5, as you could see, 0.5.

545
00:37:31,290 --> 00:37:32,700
Let's take this off.

546
00:37:33,690 --> 00:37:39,090
Um, 0.5 no longer has a probability of about 0.35 of being picked.

547
00:37:39,120 --> 00:37:45,630
0.5 has the probability now of about zero of being picked, while negative five also still has a probability

548
00:37:45,630 --> 00:37:47,160
of about zero of being picked.

549
00:37:47,160 --> 00:37:51,270
But on the other hand, as you could see here, let's take this off.

550
00:37:51,300 --> 00:37:57,330
You see that values like five have much higher probability of being picked seven, eight, six.

551
00:37:57,360 --> 00:38:00,180
They now have much higher probabilities of being picked.

552
00:38:00,210 --> 00:38:07,380
Now, this means that if this was a hundred or if we were able to get to a hundred, then we'll be values

553
00:38:07,380 --> 00:38:15,480
like 97 or 98, 99, 100, 101, 102.

554
00:38:15,480 --> 00:38:21,600
And this explains why when we run this code with this mean we had values surrounding 100, and that's

555
00:38:21,600 --> 00:38:27,870
simply because those values surrounding the mean have um higher probabilities of being picked.

556
00:38:28,620 --> 00:38:33,540
Now let's take this back to zero and then talk about the standard deviation.

557
00:38:33,540 --> 00:38:37,470
So we have the zero there we go to get back to zero.

558
00:38:37,470 --> 00:38:39,420
And now let's talk about the standard deviation.

559
00:38:39,420 --> 00:38:45,450
But before getting into any, um, explanations, let's modify this.

560
00:38:45,450 --> 00:38:46,860
Let's say we take ten here.

561
00:38:47,370 --> 00:38:47,610
Okay?

562
00:38:47,610 --> 00:38:49,800
It looks like the max is fixed at 2.5.

563
00:38:49,800 --> 00:38:50,220
Okay.

564
00:38:50,220 --> 00:38:52,680
So let's, let's say we have that 2.5.

565
00:38:52,680 --> 00:38:57,360
One thing you can notice is we still have this mean at zero.

566
00:38:57,390 --> 00:38:59,250
We still have our mean at zero.

567
00:38:59,280 --> 00:39:05,010
Does it make sense because we haven't changed this but our bell curve.

568
00:39:05,160 --> 00:39:05,760
Um.

569
00:39:06,800 --> 00:39:09,740
Shape now appears wider.

570
00:39:09,740 --> 00:39:12,680
So an increase in sigma.

571
00:39:12,710 --> 00:39:16,670
Sigma here is what we call the standard deviation.

572
00:39:16,670 --> 00:39:21,530
So it's what we call STD dev in the code.

573
00:39:21,530 --> 00:39:24,050
So we had the mean and the standard deviation.

574
00:39:24,050 --> 00:39:28,220
So sigma the standard deviation, the Sigma Square is the variance.

575
00:39:28,220 --> 00:39:30,950
So Sigma Square is the variance.

576
00:39:30,950 --> 00:39:40,760
Anyway, what we're trying to say here is an increase in Sigma will make this curve wider and a decrease.

577
00:39:40,760 --> 00:39:42,110
Let's decrease sigma.

578
00:39:42,140 --> 00:39:48,260
You see, a decrease in sigma makes the curve thinner and narrower.

579
00:39:49,250 --> 00:39:53,150
Now what this implies is that if we have, let's say, let's get back to this.

580
00:39:53,180 --> 00:40:02,750
If we have Sigma Square as 2.5, there are much higher chances now that we could, um, randomly select

581
00:40:02,780 --> 00:40:05,150
negative five as compared to before.

582
00:40:05,150 --> 00:40:11,580
So if this is negative five here, you see there's a slightly higher probability of negative five and

583
00:40:11,580 --> 00:40:15,360
peaked as compared to when we reduced this.

584
00:40:15,390 --> 00:40:20,490
You see, when we reduce this, um, you see negative five years, practically zero.

585
00:40:20,490 --> 00:40:28,080
But when we increase, see negative five is at least this time around having some negligible value.

586
00:40:28,800 --> 00:40:32,520
And so this is essentially the role that standard deviation plays.

587
00:40:32,730 --> 00:40:41,130
Now if we reduce this again, we find that even 0.5 because this is 0.5 around here, even 0.5, let's

588
00:40:41,130 --> 00:40:42,540
take this off.

589
00:40:42,540 --> 00:40:52,740
Even 0.5, which used to have a probability of about 0.35 of occurring now has almost no chance of being

590
00:40:52,740 --> 00:40:53,370
picked.

591
00:40:53,400 --> 00:40:56,100
Let's increase it back and set it back to zero.

592
00:40:56,130 --> 00:40:56,760
Okay.

593
00:40:57,480 --> 00:40:58,470
And so that is it.

594
00:40:58,470 --> 00:41:01,080
At this point, we could modify this.

595
00:41:01,110 --> 00:41:05,400
We could take this to six and then take this to 2.5.

596
00:41:05,400 --> 00:41:13,410
And you see that we could take values Now between zero, see, we go from zero to about, um, 11.

597
00:41:13,440 --> 00:41:21,450
With that said, we will then look at the uniform distribution or how to generate random numbers or

598
00:41:21,450 --> 00:41:24,450
random values drawn from a uniform distribution.

599
00:41:24,450 --> 00:41:28,230
So again, we'll just copy this out and then get back to the code.

600
00:41:28,260 --> 00:41:30,360
We will paste this here.

601
00:41:30,510 --> 00:41:31,830
There we go.

602
00:41:31,830 --> 00:41:33,360
We have the shape.

603
00:41:33,630 --> 00:41:37,620
Let's pick, um, this, uh, one.

604
00:41:37,620 --> 00:41:38,190
Okay.

605
00:41:38,190 --> 00:41:40,440
And then minimum value zero.

606
00:41:40,440 --> 00:41:42,030
And now we have maximum value.

607
00:41:42,030 --> 00:41:47,340
So you see that unlike here, where we had the minimum, the mean and the standard deviation, now we

608
00:41:47,340 --> 00:41:51,540
have instead of a minimum value and a maximum value.

609
00:41:51,540 --> 00:41:54,330
So let's, let's, let's leave, leave it at this.

610
00:41:54,330 --> 00:42:00,000
And then let's say we have random tensor, random tensor.

611
00:42:00,030 --> 00:42:00,570
Okay?

612
00:42:00,570 --> 00:42:02,250
So let's print this out.

613
00:42:02,640 --> 00:42:04,680
Let's print out our random tensor.

614
00:42:05,370 --> 00:42:06,270
There we go.

615
00:42:06,270 --> 00:42:08,870
We have random tensor.

616
00:42:08,870 --> 00:42:11,960
Let's increase this so we have many more values.

617
00:42:11,990 --> 00:42:13,610
Five run that.

618
00:42:13,850 --> 00:42:14,540
Okay.

619
00:42:14,540 --> 00:42:16,700
You see, we have this values.

620
00:42:16,730 --> 00:42:21,950
Now let's let's say we change this max value and say it's um.

621
00:42:23,000 --> 00:42:25,200
880 or let's say eight.

622
00:42:25,220 --> 00:42:26,330
Okay, let's say eight.

623
00:42:26,360 --> 00:42:27,410
Let's run that.

624
00:42:27,410 --> 00:42:30,410
And what do you notice now is you have much larger values.

625
00:42:30,410 --> 00:42:33,010
Well, values between 0 and 8.

626
00:42:33,020 --> 00:42:40,540
But, um, before the values we're getting were values ranging between 0 and 1.

627
00:42:40,550 --> 00:42:46,280
Now, this tells us that most probably this maximum value by default is one.

628
00:42:46,280 --> 00:42:49,130
So here it is, default to one.

629
00:42:49,130 --> 00:42:52,640
You could always make use of the documentation whenever you're in doubt.

630
00:42:52,640 --> 00:42:54,620
So let's get back here.

631
00:42:54,620 --> 00:43:00,080
You see, we will take this to 100 and then see what we get.

632
00:43:00,080 --> 00:43:04,040
You see, we have this values now between 0 and 100.

633
00:43:04,070 --> 00:43:09,440
Now the question you may be asking yourself is what then is the difference between this uniform and

634
00:43:09,440 --> 00:43:11,600
this normal distribution?

635
00:43:11,600 --> 00:43:19,130
So let's get back again here, um, in our probability playground and then let's pick out our uniform.

636
00:43:19,130 --> 00:43:23,630
So as you could see, your many other probability distributions.

637
00:43:23,630 --> 00:43:28,130
But we are going to focus on the normal distribution and the uniform distribution.

638
00:43:28,130 --> 00:43:32,330
So we get into the uniform distribution and here is what we get.

639
00:43:32,330 --> 00:43:40,940
So we have A and B Now this is like our main value, which we saw in the code, and this is like our

640
00:43:40,940 --> 00:43:42,380
max Val.

641
00:43:42,380 --> 00:43:48,740
So when we say meanwhile, negative one, max, Val one, obviously our values will fall in this range.

642
00:43:48,740 --> 00:43:53,240
Now by default, this is zero and this is one on TensorFlow.

643
00:43:53,240 --> 00:43:57,290
So, um, that's why you saw the values ranging between 0 and 1.

644
00:43:58,610 --> 00:44:02,390
Now, as the term goes, it's actually uniform.

645
00:44:02,390 --> 00:44:13,250
So this means that all this values here have equal chances or probabilities of being picked.

646
00:44:14,620 --> 00:44:19,210
And so unlike the normal distribution where we would have something like this.

647
00:44:20,350 --> 00:44:21,490
Something like this.

648
00:44:21,520 --> 00:44:27,160
Now we have this square instead or this rectangle.

649
00:44:27,940 --> 00:44:35,080
And so simply here, all we're doing is picking the range of values which we want to have or which we

650
00:44:35,080 --> 00:44:39,100
want to be outputted so we could get here, increase this.

651
00:44:39,760 --> 00:44:42,400
We you cannot you cannot the mean cannot pass.

652
00:44:42,400 --> 00:44:44,470
The cannot be greater than the max.

653
00:44:44,470 --> 00:44:45,610
So that makes sense.

654
00:44:45,610 --> 00:44:47,170
Let's reduce this, reduce that.

655
00:44:47,170 --> 00:44:50,160
So from -4 to 4, you see, we take all the values.

656
00:44:50,170 --> 00:44:51,340
Well, that's it.

657
00:44:51,370 --> 00:44:52,630
You see, there we go.

658
00:44:52,630 --> 00:44:54,490
We go from -1 to 2.

659
00:44:54,520 --> 00:44:55,270
That's it.

660
00:44:56,270 --> 00:45:01,260
Now, one great thing is also the fact that we could modify this and have it.

661
00:45:01,280 --> 00:45:04,530
So let's run this and see what we get.

662
00:45:04,550 --> 00:45:06,320
You see, we have only integers now.

663
00:45:06,320 --> 00:45:09,230
Now let's say we had known known.

664
00:45:09,230 --> 00:45:10,400
Let's run that.

665
00:45:11,270 --> 00:45:12,500
You see, we have an error.

666
00:45:12,530 --> 00:45:18,170
Must specify a max val in the case where the data type is integer.

667
00:45:18,170 --> 00:45:22,610
So this actually, um, written out here in the documentation.

668
00:45:22,610 --> 00:45:26,240
So you can see here now that you need to have this max.

669
00:45:26,240 --> 00:45:29,180
Val So let's change that to, let's say 1000.

670
00:45:29,210 --> 00:45:33,740
So you will get values ranging between 0 and 1000.

671
00:45:33,740 --> 00:45:36,800
So we have five values here from the shape.

672
00:45:36,800 --> 00:45:45,410
We could change this, let's say five by five, and then all those values range between 0 and 1000.

673
00:45:45,590 --> 00:45:50,870
Another argument which we haven't spoken of so far is this seed argument.

674
00:45:50,870 --> 00:46:00,420
And here we told that this seed argument when used in combination with TensorFlow random set seed,

675
00:46:01,090 --> 00:46:07,830
will be able to create a reproducible sequence of tensors across multiple calls.

676
00:46:08,370 --> 00:46:16,380
And so in cases where we want to produce reproducible experiments, we want to set this global seed

677
00:46:16,380 --> 00:46:26,190
value and also the seed argument value in this uniform or let's say normal function.

678
00:46:26,610 --> 00:46:28,830
So let's go ahead and copy this out.

679
00:46:28,860 --> 00:46:30,300
We'll get back to the code.

680
00:46:31,140 --> 00:46:32,490
There we go.

681
00:46:32,490 --> 00:46:34,170
Let's just run this right here.

682
00:46:34,830 --> 00:46:38,940
Let's take off some parts and print this out.

683
00:46:38,940 --> 00:46:41,160
So we print this out.

684
00:46:42,120 --> 00:46:49,410
Then we modify the shape and the max values so we have exactly the same value for the seed here, which

685
00:46:49,410 --> 00:46:49,830
is ten.

686
00:46:49,830 --> 00:46:52,380
And then here we set this global seed to five.

687
00:46:52,410 --> 00:46:53,520
Let's run this.

688
00:46:54,390 --> 00:46:59,340
You see it outputs four, three, one, four, three, two, one, one, one, and one, three, three.

689
00:46:59,370 --> 00:47:01,530
Now let's create another cell.

690
00:47:02,430 --> 00:47:03,990
Let's copy this.

691
00:47:04,200 --> 00:47:05,490
There we go.

692
00:47:05,490 --> 00:47:06,750
Paste this out here.

693
00:47:06,750 --> 00:47:11,940
And you see, we have the same global seed, and then we have the seed of ten.

694
00:47:11,940 --> 00:47:13,380
Now let's run this again.

695
00:47:14,060 --> 00:47:19,940
And as you could see, we have exactly the same output as this one.

696
00:47:19,970 --> 00:47:20,170
See?

697
00:47:20,210 --> 00:47:27,480
Four, three, 1431432, four, three, two, one, 1111, one and one three, three.

698
00:47:27,860 --> 00:47:34,510
Now, obviously modifying this and taking for example, one gives us something different.

699
00:47:34,520 --> 00:47:39,620
But if we take ten again, you see, we should have exact same output.

700
00:47:40,040 --> 00:47:45,920
Now you also see that here when we take this off, if we take this off and rerun this cell, you see

701
00:47:45,920 --> 00:47:47,180
we have different outputs.

702
00:47:47,180 --> 00:47:50,390
But when we get back here, let's let's run this again.

703
00:47:50,420 --> 00:47:53,060
See, we have another set of different outputs.

704
00:47:53,060 --> 00:47:58,340
But when we take this run that you see, we have exact same output we had already.

705
00:47:58,790 --> 00:48:04,550
And now if you want to have more details about certain seeds, you could always check out this, the

706
00:48:04,550 --> 00:48:05,450
documentation.
