1
00:00:00,810 --> 00:00:08,360
All right, you know how to slice lists 0 to 1

2
00:00:08,400 --> 00:00:13,880
will give you the first item of the list, and 0 to 2 as will give you  the first and the second item of the list and

3
00:00:13,890 --> 00:00:16,800
so on. With Numpy arrays

4
00:00:16,800 --> 00:00:23,640
you do basically the same thing except with Numpy arrays sometimes you have two or more dimentionals

5
00:00:23,940 --> 00:00:25,560
or three.

6
00:00:25,560 --> 00:00:31,760
So let me go ahead and I'll create, I'll start with a two dimensional array.

7
00:00:32,190 --> 00:00:35,430
So I'll get that from this variable.

8
00:00:35,430 --> 00:00:38,950
So this is the Numpy array we'll be working with.

9
00:00:39,150 --> 00:00:47,540
And yet if you want to extract this number here, this here, this one and this.

10
00:00:47,670 --> 00:00:49,840
So these four numbers.

11
00:00:50,040 --> 00:00:56,040
Well you'd first need to set the index of the rows that you want to slice.

12
00:00:56,190 --> 00:01:03,340
So that would be zero to two which gives you the first two rows.

13
00:01:03,480 --> 00:01:08,660
Actually we can try that and you'll see that you get the first two rows.

14
00:01:08,670 --> 00:01:16,020
Now if you want only this portion here, so these two numbers, and these two you would want to pass

15
00:01:17,430 --> 00:01:31,910
a comma there and then the index for the columns which would be you know 0 here, 1, so 2,  3. And yeah, 2 to 4 maybe. Yeah,  that should do it.

16
00:01:32,350 --> 00:01:35,100
And that's it.

17
00:01:35,220 --> 00:01:37,610
That means you have this indexing system.

18
00:01:37,610 --> 00:01:45,110
So you start from 0 for rows, then the second row is 1 and 2 and so on. For columns the same thing.

19
00:01:45,380 --> 00:01:50,120
0 1 2 3 and 4.

20
00:01:50,540 --> 00:01:55,310
And actually if you like you can see the shape of your Numpy array.

21
00:01:55,550 --> 00:02:01,010
So it's 3 by 5 which means 0 to 2, and 0 to 4.

22
00:02:01,160 --> 00:02:01,780
Great.

23
00:02:02,090 --> 00:02:06,410
And of course you can use the convention of list indexing.

24
00:02:06,650 --> 00:02:11,950
So you can pass zero and everything after that or just like that.

25
00:02:12,020 --> 00:02:17,780
So you get all the rows and only the columns from two to three.

26
00:02:17,800 --> 00:02:24,240
Similarly you can get only one value if you like.

27
00:02:24,460 --> 00:02:34,520
Not particularly this one because three is out of the bounds for axis zero, so axis zero is a horizontal axis which

28
00:02:34,550 --> 00:02:37,950
says that there is no row with index 3.

29
00:02:38,320 --> 00:02:41,370
So we said it's 0 1 2.

30
00:02:41,470 --> 00:02:47,500
So let's pass 2 there and you get 182 which is the very last

31
00:02:47,500 --> 00:02:47,850
item

32
00:02:47,870 --> 00:02:49,340
of the Numpy array.

33
00:02:49,830 --> 00:02:51,360
Yeah that's about indexing.

34
00:02:51,430 --> 00:02:54,170
How about iterating through a Numpy array?

35
00:02:54,850 --> 00:02:56,820
Well there are two ways to do that.

36
00:02:56,830 --> 00:03:09,730
The first way is to say, let's say for i in your Numpy array print i, and what that will do is it will print

37
00:03:09,730 --> 00:03:14,410
out the rows of your Numpy arrays.

38
00:03:14,470 --> 00:03:18,900
So what this i axis is in your Numpy arrays is the rows.

39
00:03:18,970 --> 00:03:24,670
So each the ration it gets the first row and it prints that out in the first iteration, then the second

40
00:03:24,670 --> 00:03:27,770
one, and then the third one.

41
00:03:27,840 --> 00:03:35,530
And if you want to iterate through columns you'd want to access the transposed version of your Numpy array

42
00:03:36,460 --> 00:03:38,260
and that's how you do it.

43
00:03:38,710 --> 00:03:49,040
And also if you want to iterate value by value, you'd say for i in im_g.flat

44
00:03:51,830 --> 00:03:55,670
print i.

45
00:03:55,800 --> 00:04:00,190
So this property what it does is it allows you to access the values

46
00:04:00,190 --> 00:04:06,130
of your Numpy array one by one. And that's about indexing, slicing, and iterating.

47
00:04:06,230 --> 00:04:07,600
I'll see you in the next lecture!

