1
00:00:00,110 --> 00:00:03,980
Let's now dive into this new section on TensorFlow indexing.

2
00:00:04,010 --> 00:00:08,540
So let's suppose we have this tensor which we'll call tensor indexed.

3
00:00:08,540 --> 00:00:13,700
And we simply define this 1D tensor with some values.

4
00:00:13,700 --> 00:00:14,810
So we have

5
00:00:14,810 --> 00:00:20,360
24904567.

6
00:00:20,360 --> 00:00:22,940
And then let's run this.

7
00:00:22,940 --> 00:00:27,560
And then we say okay we want to get um let's say this value for now.

8
00:00:27,560 --> 00:00:33,080
To obtain this value for we are going to make use of its index.

9
00:00:33,780 --> 00:00:37,620
In general, in programming, the first index is zero.

10
00:00:37,620 --> 00:00:47,160
So this is going to be 012, three, four, five six and then seven.

11
00:00:47,160 --> 00:00:54,450
So if we want to get this foyer we're going to have to specify the index one.

12
00:00:54,450 --> 00:01:00,030
If we want to get two we have to specify the index zero and so on and so forth for the rest.

13
00:01:00,030 --> 00:01:08,130
So let's after running this that's after getting or creating this tensor index, we could simply print

14
00:01:08,130 --> 00:01:13,740
out tensor index and then specify an index.

15
00:01:13,740 --> 00:01:16,740
So let's say we we want to pick out the start.

16
00:01:16,740 --> 00:01:19,020
So ten tensor index three.

17
00:01:20,100 --> 00:01:22,140
We'll put this three in a square bracket.

18
00:01:22,140 --> 00:01:23,190
We run that.

19
00:01:23,730 --> 00:01:29,640
You see that it's going to give us the value zero which matches with this arrangement.

20
00:01:29,640 --> 00:01:36,750
Now if we say we want to get the last element or if we want to get the the first element, then we'll

21
00:01:36,750 --> 00:01:37,740
specify zero.

22
00:01:37,740 --> 00:01:40,890
So the zeroth index we run that.

23
00:01:41,620 --> 00:01:43,780
And you see, we should get two.

24
00:01:44,050 --> 00:01:45,280
See, we have two.

25
00:01:45,280 --> 00:01:47,500
Now, if you want to have the last element.

26
00:01:47,500 --> 00:01:49,870
So let's say we want to have the last element.

27
00:01:49,870 --> 00:01:57,190
We could pick seven or we could say we want to have tensor indexed.

28
00:01:57,280 --> 00:01:59,590
And then we say negative one.

29
00:01:59,590 --> 00:02:03,880
So when you specify negative one then you're specifying the last element.

30
00:02:04,150 --> 00:02:10,030
Um given that we know the, the the exact index for the last element, which in this case is seven,

31
00:02:10,030 --> 00:02:11,500
then we could specify seven.

32
00:02:11,500 --> 00:02:13,690
So let's run this and then see what we get.

33
00:02:14,820 --> 00:02:15,720
There we go.

34
00:02:15,720 --> 00:02:18,180
You see, we have seven and then we have seven.

35
00:02:18,180 --> 00:02:24,810
So that's how easy it is for us to, uh, obtain a value based on its position in the tensor.

36
00:02:24,840 --> 00:02:31,350
Now let's say we want to get a segment or part of this 1D tensor.

37
00:02:31,350 --> 00:02:32,670
Let's say we want to get this segment.

38
00:02:32,670 --> 00:02:34,860
We want to get 4904.

39
00:02:34,860 --> 00:02:41,790
Now this 4904, as we could see here matches with the indices 1 to 4.

40
00:02:42,180 --> 00:02:44,070
Or let's, let's let's pick another one.

41
00:02:44,070 --> 00:02:45,210
Let's say four.

42
00:02:45,450 --> 00:02:48,270
Um 90456.

43
00:02:48,270 --> 00:02:51,330
This matches with 1 to 6 you see.

44
00:02:51,330 --> 00:02:54,780
So let's just um, run this and see what we get.

45
00:02:54,780 --> 00:02:56,850
Tensor indexed.

46
00:02:57,120 --> 00:03:06,060
Um, and here instead of um, selecting each and every one of this, we would do one because remember

47
00:03:06,060 --> 00:03:10,260
one would pick out this elements 490456.

48
00:03:10,260 --> 00:03:14,070
Then we will specify the indices um one right up to six.

49
00:03:14,700 --> 00:03:22,410
But we are not going to say one, two, three, four, five and then six and then try to run that.

50
00:03:24,750 --> 00:03:26,040
You see, we get an error here.

51
00:03:26,040 --> 00:03:33,960
So what we are going to do is we're going to say we want to go from 1 to 6 by specifying or by putting

52
00:03:33,960 --> 00:03:35,070
between one.

53
00:03:35,070 --> 00:03:39,510
That's the start index and the end index a colon.

54
00:03:39,510 --> 00:03:45,150
So we just put that colon, we run that and there we go.

55
00:03:45,150 --> 00:03:47,730
You see we have this part which we wanted.

56
00:03:47,730 --> 00:03:52,050
That's 494490456.

57
00:03:52,050 --> 00:03:59,610
But when you look at the those outputs actually 49045 now what this tells us is actually when we say

58
00:03:59,610 --> 00:04:07,440
one right up to six, we're going from um, one, uh, let's, let's put it out this way.

59
00:04:07,440 --> 00:04:11,790
When we say one up to six, we're actually going from one right up to.

60
00:04:12,660 --> 00:04:14,970
Six minus one.

61
00:04:15,000 --> 00:04:18,030
So we're actually going from one right up to five.

62
00:04:18,540 --> 00:04:28,770
And so if we want to go or if we want to pick out 490456, then we'll need to say here that we want

63
00:04:28,770 --> 00:04:29,880
to go to seven.

64
00:04:29,880 --> 00:04:35,940
So, so such that we'll go from 1 to 7 and or we'll go from 1 to 7 minus one.

65
00:04:35,940 --> 00:04:37,140
That will be 1 to 6.

66
00:04:37,770 --> 00:04:39,180
So let's take that off.

67
00:04:39,180 --> 00:04:40,230
Run that again.

68
00:04:40,230 --> 00:04:43,950
And you can see now that we have 490456.

69
00:04:43,950 --> 00:04:50,490
So in general what we'll do is um, if we want to go from um a given start.

70
00:04:50,490 --> 00:04:52,980
So we'll do a start to the end.

71
00:04:52,980 --> 00:04:57,420
But instead of um, end, we'll do start to end minus one.

72
00:04:58,250 --> 00:05:05,660
And so in general, if you want to go from index start right up to index end, we should instead do

73
00:05:05,660 --> 00:05:08,960
tensor slice or tensor index.

74
00:05:09,410 --> 00:05:18,830
Um, start right up to end plus one so that uh when we do n plus one minus one it falls back at end.

75
00:05:18,830 --> 00:05:19,760
So that's it.

76
00:05:19,760 --> 00:05:26,030
Now you could, um, pause the video at this point and try to, um, do for example, or get this first

77
00:05:26,030 --> 00:05:28,850
tree, you see that you will have two, four, nine.

78
00:05:28,850 --> 00:05:30,740
That's going to be 0 to 2.

79
00:05:31,310 --> 00:05:33,260
Uh, hopefully you got the answer.

80
00:05:33,260 --> 00:05:34,580
Let's just get that done.

81
00:05:34,580 --> 00:05:38,930
So we'll do tensor tensor um index.

82
00:05:38,930 --> 00:05:41,960
And then we'll do because we're going from 0 to 2.

83
00:05:41,990 --> 00:05:45,620
So we'll do 0 to 2 plus one.

84
00:05:45,620 --> 00:05:46,820
You see let's run.

85
00:05:46,820 --> 00:05:52,280
That could take this off so that we could see the the the original tensor indexed.

86
00:05:52,280 --> 00:05:53,900
So let's take that off.

87
00:05:53,900 --> 00:05:54,740
There we go.

88
00:05:54,740 --> 00:05:57,020
You see um 0 to 2 plus one.

89
00:05:57,020 --> 00:05:59,300
You see we have 249.

90
00:05:59,300 --> 00:06:06,500
Now if we're starting from the very first index, if we're starting from the zeroth index then we must

91
00:06:06,500 --> 00:06:07,190
not put this.

92
00:06:07,190 --> 00:06:10,970
So, uh, taking the zero off already tells us that it's actually zero.

93
00:06:10,970 --> 00:06:14,630
So we could have the zero, or you may not have the zero.

94
00:06:14,630 --> 00:06:16,310
So you see, it's the same answer.

95
00:06:16,310 --> 00:06:22,790
Now, if let's say we want to get from zero right up to the end, what we'll do here, we will have

96
00:06:22,790 --> 00:06:24,020
three right up to seven.

97
00:06:24,020 --> 00:06:30,230
So we'll do three um, up to seven remember plus one.

98
00:06:30,230 --> 00:06:32,390
So we run that again.

99
00:06:32,390 --> 00:06:40,280
And you see we, we should have 0456 704 567 exactly as we expect.

100
00:06:40,280 --> 00:06:44,750
Now given that we're going right up to the end, we could also decide not to put anything.

101
00:06:44,750 --> 00:06:50,510
So if you're going or if you're starting from the, the first the zeroth index, you may not put anything.

102
00:06:50,660 --> 00:06:54,470
Um, if you're going right up to the end, you may also decide not to put any value.

103
00:06:54,470 --> 00:06:56,480
So let's run that and see what we get.

104
00:06:57,050 --> 00:07:07,880
You see, we have exact same, um, output 04567, the same as we would have with um, seven plus 104567.

105
00:07:07,880 --> 00:07:08,660
So that's it.

106
00:07:08,660 --> 00:07:14,180
Now if you want to go right up to the last but one value, you could say we're going from three right

107
00:07:14,180 --> 00:07:15,680
up to minus one.

108
00:07:15,680 --> 00:07:24,830
So remember when we specified, um or when we had tensor tensor indexed um and then we specified minus

109
00:07:24,830 --> 00:07:25,490
one.

110
00:07:25,490 --> 00:07:30,830
The value we got was seven which was the last value.

111
00:07:30,830 --> 00:07:39,050
But when we um specify or when we go from a start index to that end index and we specify this minus

112
00:07:39,050 --> 00:07:48,620
one, obviously we'll go from start to end and the end will instead be the the value before the actual

113
00:07:48,620 --> 00:07:49,010
end.

114
00:07:49,010 --> 00:07:54,920
So it's just like what we've seen already where if we're going from let's say um, three let's take

115
00:07:54,920 --> 00:07:55,610
the start off.

116
00:07:55,610 --> 00:08:02,870
If we're going from three to to seven, then what we will actually get by doing this, if we just took

117
00:08:02,870 --> 00:08:12,200
3 to 7, what will actually get will be 3 to 2 six, you see.

118
00:08:12,200 --> 00:08:18,410
So when we do three two negative one is the same as going from 3 to 7.

119
00:08:18,410 --> 00:08:20,930
So that's actually um 3 to 6.

120
00:08:20,930 --> 00:08:26,510
So when let's run this you see we should get 0456.

121
00:08:26,510 --> 00:08:27,350
So that's it.

122
00:08:27,350 --> 00:08:32,450
Now if we want to get to the second to the last, that's 3 to -2.

123
00:08:32,690 --> 00:08:34,580
You see now we have 045.

124
00:08:34,580 --> 00:08:39,770
Then we could do third to the last we have or we should have zero four.

125
00:08:39,770 --> 00:08:40,730
So on and so forth.

126
00:08:40,730 --> 00:08:41,720
So that's it.

127
00:08:41,720 --> 00:08:45,860
Then another thing we could do is let's say we let's get back to say six.

128
00:08:45,860 --> 00:08:49,760
And the thing we could do is we could, um, get these values and steps.

129
00:08:49,760 --> 00:08:54,950
Let's take that from the beginning to the, to the, to the seat, or let's even take the seventh value.

130
00:08:54,950 --> 00:08:56,210
So let's go to seven.

131
00:08:56,210 --> 00:09:03,080
So if we run this we have from 0 to 7 then we have 2490456.

132
00:09:03,080 --> 00:09:03,830
That's fine.

133
00:09:03,830 --> 00:09:08,630
Now we could um get this values in steps of two.

134
00:09:08,660 --> 00:09:14,720
So if we put two see specifying this two would make us get two.

135
00:09:14,720 --> 00:09:16,370
And then we skip this one.

136
00:09:16,370 --> 00:09:20,450
Nine will skip this one four we'll skip this one and then six.

137
00:09:20,450 --> 00:09:24,530
So let's just run this let's print this out here.

138
00:09:24,530 --> 00:09:27,740
Tensor indexed.

139
00:09:27,890 --> 00:09:31,910
Tensor indexed and let's say goes 0 to 7.

140
00:09:31,910 --> 00:09:34,490
Let's write out explicitly 0 to 7.

141
00:09:34,490 --> 00:09:37,220
And then here we have 0 to 7.

142
00:09:37,220 --> 00:09:38,300
Bear with steps of two.

143
00:09:38,300 --> 00:09:39,860
So let's print this out.

144
00:09:40,460 --> 00:09:41,420
Let's print that out.

145
00:09:41,420 --> 00:09:42,410
There we go.

146
00:09:42,500 --> 00:09:47,150
So as you could see we have 2490456.

147
00:09:47,150 --> 00:09:52,040
But now uh when we specify steps of two we'll take two and then we'll skip four.

148
00:09:52,040 --> 00:09:53,120
We get nine.

149
00:09:53,150 --> 00:09:54,560
See that's nine here.

150
00:09:54,770 --> 00:09:56,360
And then we skip zero.

151
00:09:56,360 --> 00:09:57,440
We get four.

152
00:09:58,320 --> 00:10:01,980
Does four year and then we skip, um, six.

153
00:10:01,980 --> 00:10:03,060
All right, I will skip five.

154
00:10:03,060 --> 00:10:04,800
And then we get six and that's six there.

155
00:10:04,800 --> 00:10:05,640
So that's it.

156
00:10:05,640 --> 00:10:09,180
So essentially this is the same as um having one.

157
00:10:09,180 --> 00:10:11,130
So not skipping any value.

158
00:10:11,130 --> 00:10:11,910
So that's it.

159
00:10:11,910 --> 00:10:15,090
We've just looked at indexing with 1D tensors.

160
00:10:15,090 --> 00:10:18,270
So let's take an example of a two dimensional tensor.

161
00:10:18,270 --> 00:10:24,030
So here we have again tensor um indexed tensor indexed.

162
00:10:24,450 --> 00:10:27,360
And then we have this 2D tensor.

163
00:10:28,440 --> 00:10:29,940
We simply fill out those values.

164
00:10:29,940 --> 00:10:33,150
So we have 23456.

165
00:10:33,330 --> 00:10:39,420
And then we have say 90421.

166
00:10:40,430 --> 00:10:50,000
And then we have 001 or well 000017 um, zero.

167
00:10:50,000 --> 00:10:50,540
Okay.

168
00:10:50,540 --> 00:10:58,220
So we have this tensor which turns out to be a five or rather three by five tensor 2D.

169
00:10:58,220 --> 00:11:00,800
So we have to add this square bracket.

170
00:11:01,340 --> 00:11:02,240
There we go.

171
00:11:02,240 --> 00:11:06,080
We add the square bracket here and at this position.

172
00:11:06,080 --> 00:11:08,570
So this is our 2D tensor.

173
00:11:08,840 --> 00:11:12,530
And then we want to get a specific value.

174
00:11:12,530 --> 00:11:18,230
Now let's suppose that we want to get the value or this value nine at this position.

175
00:11:18,230 --> 00:11:23,570
So what we'll do is we'll start by saying um how many rows do we have.

176
00:11:23,570 --> 00:11:26,390
We have one two, three.

177
00:11:26,390 --> 00:11:32,570
And what we'll do is we'll locate the row in which this nine is found and the column.

178
00:11:32,570 --> 00:11:37,550
So this is the first row second row and third row.

179
00:11:37,550 --> 00:11:48,470
While this is the first column that's 290 first um colon second colon, third colon fourth colon and

180
00:11:48,470 --> 00:11:49,610
fifth column.

181
00:11:49,640 --> 00:11:53,690
Now this nine is found on the second row.

182
00:11:53,690 --> 00:12:02,360
But since we start counting from one from zero we have the zeroth row and the first row.

183
00:12:02,360 --> 00:12:07,490
So here we'll say we want to have tensor tensor indexed.

184
00:12:07,490 --> 00:12:10,640
And then we'll specify we want to have one.

185
00:12:10,640 --> 00:12:14,810
So index one because this is zero this is one.

186
00:12:14,810 --> 00:12:16,070
And then this is two.

187
00:12:16,100 --> 00:12:23,060
Now for the colon we have colon zero because this is the first colon or this is the zeroth colon or

188
00:12:23,060 --> 00:12:29,570
colon with index zero, colon index one, index two, index three and then index four.

189
00:12:29,570 --> 00:12:33,680
So since this is index zero we're going to have zero.

190
00:12:33,680 --> 00:12:36,680
But we separate this tool with a comma.

191
00:12:36,680 --> 00:12:42,170
So unlike when the 1D where we didn't separate with a comma because obviously it's one dimensional.

192
00:12:42,170 --> 00:12:44,120
Now we have two dimensions.

193
00:12:44,120 --> 00:12:48,710
So the that to the left of the comma is the first dimension.

194
00:12:48,710 --> 00:12:51,650
That to the right of the comma is the second dimension.

195
00:12:51,950 --> 00:12:57,770
Um essentially this is the rows uh to the left obviously rows and then columns.

196
00:12:57,770 --> 00:13:00,500
So let's run this and then see what we get.

197
00:13:00,650 --> 00:13:06,920
See we have um this tensor and the value in this tensor is nine.

198
00:13:06,920 --> 00:13:07,700
So that's it.

199
00:13:07,700 --> 00:13:09,290
So you see we obtain nine.

200
00:13:09,290 --> 00:13:11,660
Now let's say we want to get this two right here.

201
00:13:11,750 --> 00:13:14,150
So it will be the same row but different column.

202
00:13:14,150 --> 00:13:17,480
So this is 0123.

203
00:13:17,480 --> 00:13:19,610
So here we replace zero with three.

204
00:13:19,610 --> 00:13:22,340
We run that again and we should get two.

205
00:13:22,370 --> 00:13:23,390
So that's fine.

206
00:13:23,390 --> 00:13:27,770
Now let's suppose we want to get um this 042.

207
00:13:27,770 --> 00:13:29,720
Or let's say we want to get 170.

208
00:13:29,720 --> 00:13:31,880
Let's say we want to get this 170.

209
00:13:31,880 --> 00:13:36,380
Now um, unlike here where we had a single value.

210
00:13:36,380 --> 00:13:38,510
So we just pick out a specific index.

211
00:13:38,510 --> 00:13:40,520
Now we have a range.

212
00:13:40,520 --> 00:13:45,290
So just like what we are seeing with the 1D tensor where we could pick out the range.

213
00:13:45,290 --> 00:13:47,690
Now we're also going to pick out this range of values.

214
00:13:47,690 --> 00:13:50,750
So we have 170 which we want to pick out.

215
00:13:50,750 --> 00:13:56,090
What we'll do is we'll go again zeroth row first row second row.

216
00:13:56,090 --> 00:13:58,370
So here we pick second row.

217
00:13:58,400 --> 00:13:59,240
There we go.

218
00:13:59,240 --> 00:14:01,850
So up because all these values fall in the second row.

219
00:14:01,850 --> 00:14:03,320
We just pick the second row.

220
00:14:03,320 --> 00:14:10,190
And then for the columns because the values we want to pick um fall in a range of columns that this

221
00:14:10,190 --> 00:14:11,930
is zero, one, two.

222
00:14:11,960 --> 00:14:13,010
This is where one starts.

223
00:14:13,010 --> 00:14:16,040
So colon two is here we have two.

224
00:14:16,040 --> 00:14:19,490
Remember this is after the comma to the right of the comma.

225
00:14:19,490 --> 00:14:23,870
And then we go from two right up to this colon.

226
00:14:23,870 --> 00:14:26,720
So we have 234.

227
00:14:27,260 --> 00:14:33,170
Now again if we want to get to the fourth column then we will do four plus one just as we had seen with

228
00:14:33,170 --> 00:14:33,830
a 1D.

229
00:14:33,830 --> 00:14:36,590
So let's run this and then see what we get.

230
00:14:36,590 --> 00:14:38,360
You see we have 170.

231
00:14:38,360 --> 00:14:42,860
But if we did um two four we would have only one seven.

232
00:14:42,860 --> 00:14:47,840
So let's, let's have that four plus one and that's fine.

233
00:14:47,840 --> 00:14:49,160
So that's how we obtain this.

234
00:14:49,160 --> 00:14:52,010
Now let's say we want to obtain just six and one.

235
00:14:52,010 --> 00:14:53,900
So we want to obtain six one.

236
00:14:54,570 --> 00:14:56,370
Now in this case.

237
00:14:56,370 --> 00:15:00,750
In this case we would have um six one.

238
00:15:00,750 --> 00:15:06,420
So this six belongs to zero row zero one belongs to row two.

239
00:15:06,420 --> 00:15:11,460
So we want to go from row zero right up to row two.

240
00:15:11,490 --> 00:15:17,490
But because we want to get the specific value we'll say two plus one just as we had seen already.

241
00:15:17,490 --> 00:15:18,690
So two plus one.

242
00:15:18,690 --> 00:15:20,280
And then we have the comma.

243
00:15:20,280 --> 00:15:21,780
So this is the first.

244
00:15:21,780 --> 00:15:23,010
This is for the row.

245
00:15:23,010 --> 00:15:24,810
And then this is now for the columns.

246
00:15:24,810 --> 00:15:26,730
So the one to the right for the columns.

247
00:15:26,730 --> 00:15:30,150
Now we are having this values on the same column.

248
00:15:30,150 --> 00:15:34,050
So we'll just simply say 01234.

249
00:15:34,050 --> 00:15:35,670
So we'll specify four.

250
00:15:35,670 --> 00:15:38,160
Run that and there we go.

251
00:15:38,160 --> 00:15:42,750
You see we have 610 because we want to have only six and one.

252
00:15:42,750 --> 00:15:45,060
We are going to take off this one from here.

253
00:15:45,060 --> 00:15:52,200
Because going from 0 to 2 is simply simply having zero and then two minus one which is one.

254
00:15:52,200 --> 00:15:53,940
So that's exactly what we want to have.

255
00:15:53,940 --> 00:15:54,960
So no need.

256
00:15:54,960 --> 00:15:56,130
Um, adding plus one.

257
00:15:56,130 --> 00:15:57,660
That was actually an error.

258
00:15:57,810 --> 00:16:01,080
We would have added plus one if we wanted to get all these elements.

259
00:16:01,080 --> 00:16:02,280
That's 610.

260
00:16:02,280 --> 00:16:05,910
So let's run this again and see what we obtain.

261
00:16:05,940 --> 00:16:07,200
See we have six one.

262
00:16:07,200 --> 00:16:09,810
Now let's say we want to have 610.

263
00:16:09,810 --> 00:16:16,110
Actually if we wanted to have 610 instead of doing from 0 to 2 plus one, obviously this will give you

264
00:16:16,110 --> 00:16:17,160
610.

265
00:16:17,160 --> 00:16:21,960
We could take this off and just um, put the column.

266
00:16:21,960 --> 00:16:28,560
So now by putting the column, what you're saying is you want to work with all the rows.

267
00:16:28,560 --> 00:16:33,930
So here we work with all the rows, which is obviously the same as going from 0 to 2 plus one.

268
00:16:33,930 --> 00:16:37,470
So we run this and see what we get.

269
00:16:37,470 --> 00:16:39,510
Say we have 610.

270
00:16:39,510 --> 00:16:40,830
We could do the same for the columns.

271
00:16:40,830 --> 00:16:42,120
We could decide to.

272
00:16:42,120 --> 00:16:46,080
Obviously if you say we want to work for work with all the columns and all the rows, then you would

273
00:16:46,080 --> 00:16:48,660
have the original tensor.

274
00:16:48,660 --> 00:16:57,150
But if we pick out a specific row, let's say the row one, um, row one, or let's say we want to go

275
00:16:57,150 --> 00:16:59,880
from 0 to 1, let's run that, see what we get.

276
00:16:59,880 --> 00:17:02,700
You see we have two, three, four, five, six.

277
00:17:02,700 --> 00:17:08,490
We have this because obviously going from 0 to 1, it's like going from 0 to 1 minus one, which is

278
00:17:08,490 --> 00:17:10,800
still uh picking only the zeroth row.

279
00:17:10,800 --> 00:17:12,870
So we have two, three, four, five, six.

280
00:17:13,200 --> 00:17:15,810
Um, that's because we've picked all the columns.

281
00:17:15,810 --> 00:17:19,980
Now, another way of picking all the columns is by working with three dots.

282
00:17:19,980 --> 00:17:23,670
So if we do three dots we should get the exact same output.

283
00:17:23,670 --> 00:17:26,940
You see here we have 23456.

284
00:17:27,120 --> 00:17:31,920
Now again instead of picking or going from 0 to 1 we could just say zero.

285
00:17:31,920 --> 00:17:35,310
We run that again and we have two, three, four, five, six.

286
00:17:35,310 --> 00:17:36,270
But there is a difference.

287
00:17:36,270 --> 00:17:38,460
Let's let's put this side by side.

288
00:17:38,460 --> 00:17:43,140
So let's print out tensor indexed.

289
00:17:43,140 --> 00:17:47,760
And then we say 0 to 1.

290
00:17:47,760 --> 00:17:50,280
And then we have all the columns.

291
00:17:50,610 --> 00:17:52,680
Then yeah let's just print this out.

292
00:17:53,430 --> 00:17:54,990
So we print this out.

293
00:17:54,990 --> 00:17:57,180
And then we also print out the shape.

294
00:17:57,180 --> 00:17:58,770
So well the shape is given.

295
00:17:58,770 --> 00:17:59,970
So let's just run this.

296
00:18:00,690 --> 00:18:01,650
There we go.

297
00:18:01,650 --> 00:18:09,210
You notice that although we have the exact same values peaked, they the output has two different shapes.

298
00:18:09,210 --> 00:18:12,810
So the output of this first one is different from the output of the second one.

299
00:18:12,810 --> 00:18:20,220
And this is simply because when you pick out zero like this you are selecting a specific row.

300
00:18:20,220 --> 00:18:27,990
And so now we since you've picked out a specific role you are dealing with a 1D tensor.

301
00:18:27,990 --> 00:18:30,240
And that's why the output here is 1D.

302
00:18:30,750 --> 00:18:38,850
But when you select a set of rows, you still having to do with a 2D tensor because you this zero one,

303
00:18:38,850 --> 00:18:40,980
although it's picking only this um row.

304
00:18:40,980 --> 00:18:44,700
In this case it would have picked this, um two.

305
00:18:44,700 --> 00:18:52,560
So when you're dealing with a range there we have a 2D tensor because we this dimension still counts.

306
00:18:52,560 --> 00:18:57,450
Whereas when you pick a specific value then you're dealing with a 1D tensor.

307
00:18:57,450 --> 00:19:00,810
Now let's suppose we want to pick 4542.

308
00:19:00,810 --> 00:19:03,570
So we want to pick four five and then four two.

309
00:19:03,600 --> 00:19:06,420
What we'll do in this case is simple.

310
00:19:07,270 --> 00:19:10,810
You could pause the video and try to, to to reflect on that.

311
00:19:10,810 --> 00:19:16,030
But simply what we'll do is we will have tensor indexed.

312
00:19:16,030 --> 00:19:21,100
And then because we want to have four, five, four, two which belong to column zero.

313
00:19:21,100 --> 00:19:26,920
And column one will simply go from zero right up to one, or rather right up to two.

314
00:19:26,950 --> 00:19:28,810
Because we are we want to have zero.

315
00:19:28,810 --> 00:19:31,660
One is actually one plus one.

316
00:19:31,660 --> 00:19:33,610
That's it, which is two.

317
00:19:33,610 --> 00:19:36,340
So we go from zero right up to two.

318
00:19:36,340 --> 00:19:41,800
And then for the columns we go from this is zero, one, two, three.

319
00:19:41,800 --> 00:19:44,530
We're going from two right up to three.

320
00:19:44,530 --> 00:19:49,630
So we'll have 2 to 3 but obviously three plus one which is four.

321
00:19:49,750 --> 00:19:52,390
So let's run that and then see what we get.

322
00:19:52,390 --> 00:19:56,770
You see we have 4542 exactly as we expect.

323
00:19:57,370 --> 00:20:03,970
After exploring the 2D tensor indexing let's look at the 3D tensor indexing.

324
00:20:03,970 --> 00:20:07,330
So let's suppose that let's first of all run this.

325
00:20:07,330 --> 00:20:13,000
And then we suppose that we want to obtain this value nine which we have right here.

326
00:20:13,030 --> 00:20:14,500
Let's rearrange this a little.

327
00:20:14,500 --> 00:20:16,540
So um it's clearer.

328
00:20:17,170 --> 00:20:18,550
There we go.

329
00:20:18,550 --> 00:20:23,800
We want to have that value of nine um, which is found at this position.

330
00:20:23,800 --> 00:20:29,530
So first of all we have tensor tensor indexed.

331
00:20:29,530 --> 00:20:37,210
And then um as with the 2D where we had a single comma separating the two dimensions here we would have

332
00:20:37,210 --> 00:20:40,930
two commas separating the three dimensions.

333
00:20:40,930 --> 00:20:44,410
So we have the first, second and third dimension.

334
00:20:45,040 --> 00:20:55,060
Now if we print out this tensor indexed let's create a new cell right here and print out tensor indexed.

335
00:20:56,020 --> 00:20:58,960
You would find that let's get let's get a shape directly.

336
00:20:59,170 --> 00:21:03,640
You would find that its shape is four by two by three.

337
00:21:03,640 --> 00:21:09,430
So here we have four blocks of 2D tensors.

338
00:21:09,430 --> 00:21:12,070
There's the first there's the second there's the third.

339
00:21:12,070 --> 00:21:13,390
And this is the fourth.

340
00:21:13,390 --> 00:21:16,330
So here we have this four different blocks.

341
00:21:16,330 --> 00:21:19,390
Now nine belongs to the fourth block.

342
00:21:19,390 --> 00:21:25,060
And so if we want to obtain nine all we need to do is let's take this one off.

343
00:21:25,210 --> 00:21:32,830
All we need to do is come right here and specify that we want this, um fourth block.

344
00:21:32,830 --> 00:21:37,480
So this is 0123.

345
00:21:37,960 --> 00:21:39,760
So here we have three.

346
00:21:39,760 --> 00:21:46,870
And then once we pick out this um block that's this fourth block which is three, because we start counting

347
00:21:46,870 --> 00:21:51,520
from zero, we are then going to select a specific row.

348
00:21:51,520 --> 00:21:53,470
So this is the zeroth row.

349
00:21:53,500 --> 00:21:54,880
This is the first row.

350
00:21:54,880 --> 00:22:00,400
Or we could say first row second row knowing that we're counting from index zero um onwards.

351
00:22:00,400 --> 00:22:02,620
So this is zero.

352
00:22:02,620 --> 00:22:04,240
And this is one.

353
00:22:04,240 --> 00:22:08,200
Now nine year belongs to this um row zero.

354
00:22:08,200 --> 00:22:10,420
So here again we will say zero.

355
00:22:10,420 --> 00:22:19,420
And then for the columns this is the zeroth column or this is the first column index zero, second column

356
00:22:19,420 --> 00:22:22,480
index one and third column index two.

357
00:22:22,510 --> 00:22:24,310
So 012.

358
00:22:24,340 --> 00:22:25,870
So nine belongs to two.

359
00:22:25,900 --> 00:22:29,860
So let's um have two right there and then see what we get.

360
00:22:29,860 --> 00:22:31,930
So you see here we have nine.

361
00:22:31,930 --> 00:22:39,400
Which makes sense because um we've actually picked the exact position where nine is located.

362
00:22:39,400 --> 00:22:43,210
Now let's say we want to have um 219.

363
00:22:43,210 --> 00:22:49,990
If we want to have this 219, then it will suffice to maintain this three because 219 belongs to this,

364
00:22:50,140 --> 00:22:51,730
uh, block with index three.

365
00:22:52,180 --> 00:22:56,650
Um, and then we'll say we want to pick, um for the rows.

366
00:22:56,650 --> 00:23:01,540
We want to pick the zeroth row, but for the columns, because we want all the columns because it goes

367
00:23:01,540 --> 00:23:09,790
from zero, one, two or from 0 to 2, we are going to say we could go from 0 to 2 plus one go run that

368
00:23:09,790 --> 00:23:11,380
we should have two, one, nine.

369
00:23:11,380 --> 00:23:14,620
Or we could just simply say one to have all those values.

370
00:23:14,620 --> 00:23:16,870
We run that and that should be fine.

371
00:23:16,870 --> 00:23:18,850
See we have 219.

372
00:23:18,850 --> 00:23:28,030
Now that we have this 219, we could decide to pick out, um, let's say 214 minus three.

373
00:23:28,030 --> 00:23:36,940
In that case, again we're going to have all the rows because 214 minus three contains um, all the

374
00:23:36,940 --> 00:23:40,810
rows um are taken into consideration when picking these values.

375
00:23:40,810 --> 00:23:48,970
And then we're going to go from the zeroth column, zeroth column right up to the second to the last

376
00:23:48,970 --> 00:23:49,300
column.

377
00:23:49,300 --> 00:23:53,560
So we go 012 because obviously this is going to be two minus one.

378
00:23:53,560 --> 00:23:54,850
So let's run that.

379
00:23:54,850 --> 00:23:58,930
And then you see we have 214 minus three which makes sense.

380
00:23:58,930 --> 00:24:01,930
Or we could just simply say um minus one.

381
00:24:01,930 --> 00:24:06,610
So if we do that we should have 214 minus three now.

382
00:24:06,730 --> 00:24:13,420
Now let's suppose that for each and every block we have right here, that's for all these four blocks,

383
00:24:13,420 --> 00:24:18,370
we want to get the elements which lie on the second column.

384
00:24:18,400 --> 00:24:24,370
In that case, what we'll do is we're going to take or we're going to pick out all the different blocks,

385
00:24:24,370 --> 00:24:30,040
and then we'll pick out all the rows, and then we'll say, I want to get the elements in the second

386
00:24:30,040 --> 00:24:30,460
column.

387
00:24:30,460 --> 00:24:31,630
So let's run that.

388
00:24:32,570 --> 00:24:34,280
Are we getting an error?

389
00:24:35,270 --> 00:24:39,170
Yeah, we have multiple ellipses and slice spec not allowed.

390
00:24:39,170 --> 00:24:43,430
So we are not allowed to have multiple ellipses as we've just done.

391
00:24:43,430 --> 00:24:47,630
We just have this like this, run that and there we go.

392
00:24:47,630 --> 00:24:54,170
You see that we're going to pick now all the columns um, or all the columns of index two.

393
00:24:54,170 --> 00:24:58,160
So here we have C zero minus one.

394
00:24:58,160 --> 00:25:00,080
Here we have zero two.

395
00:25:00,110 --> 00:25:01,160
You see that here.

396
00:25:01,640 --> 00:25:03,470
Here we have zero zero.

397
00:25:03,500 --> 00:25:04,610
You can see that here.

398
00:25:04,610 --> 00:25:07,040
Here we have 932.

399
00:25:07,070 --> 00:25:08,750
You could see that right here.

400
00:25:08,750 --> 00:25:12,950
You could also just have only semicolon and run that.

401
00:25:12,950 --> 00:25:14,690
And you should have the exact same output.

402
00:25:14,690 --> 00:25:19,400
So that's it for this section on indexing we are going to move to the next section where we will work

403
00:25:19,400 --> 00:25:21,440
with math operations.
