1
00:00:01,350 --> 00:00:06,430
All right now that you know how to do slicing and iterating through Numpy arrays

2
00:00:06,420 --> 00:00:13,090
let's do some more specific operations and would be stacking Nympy arrays so concatenating 

3
00:00:13,090 --> 00:00:19,960
Numpy arrays to each other and also splitting a Numpy array to smaller arrays.

4
00:00:20,360 --> 00:00:23,560
I have this Numpy array still here.

5
00:00:23,640 --> 00:00:29,680
So let's start with stocking to Numpy arrays.

6
00:00:29,700 --> 00:00:36,510
To do that you may want to create a new variable where you will save your big array and that would be equal to Numpy

7
00:00:37,050 --> 00:00:39,850
and the method to stock two Numpy arrays�

8
00:00:40,020 --> 00:00:48,180
Actually there are two methods one with is horizontal stack so hstack. That expects for you to pass

9
00:00:48,300 --> 00:00:52,240
two or more number arrays that you want to stack horizontally.

10
00:00:52,280 --> 00:00:56,370
So let me pass.

11
00:00:56,460 --> 00:00:57,080
Im_g

12
00:00:57,090 --> 00:00:59,880
and then the same array.

13
00:00:59,880 --> 00:01:05,310
It's not a problem. If you have two different arrays you can you could do that but I'm just passing the

14
00:01:05,310 --> 00:01:06,630
same array there.

15
00:01:06,630 --> 00:01:08,710
Now if you execute this you'll get an error.

16
00:01:08,820 --> 00:01:12,540
And I want you to see this error so that you understand it.

17
00:01:12,660 --> 00:01:17,640
So it says hstack takes 1 positional argument but 2 were given.

18
00:01:17,700 --> 00:01:19,730
Which means that the hstack

19
00:01:19,770 --> 00:01:25,260
inside the brackets it gets only 1 argument but we are passing 2.

20
00:01:25,260 --> 00:01:29,430
So how do we go about concatenating 2 Numpy arrays?

21
00:01:29,460 --> 00:01:31,740
We can't just pass a Numpy array there.

22
00:01:32,040 --> 00:01:41,180
So the solution here is to have a tuple of Numpy arrays. Just like that.

23
00:01:41,190 --> 00:01:50,700
So a tuple inside the input or a hstack method. You execute that.

24
00:01:51,180 --> 00:01:54,220
And here is a stacked array. Yes, so 

25
00:01:54,240 --> 00:02:00,810
this is the first array and then the next array which in this case happens to be the same one.

26
00:02:00,810 --> 00:02:04,470
But if you want you can add more

27
00:02:09,360 --> 00:02:13,250
and you get a longer array which is not very good looking like that.

28
00:02:13,440 --> 00:02:19,060
So you can't print that out and you know you see the difference.

29
00:02:19,360 --> 00:02:24,300
So with the first array, the second and the third one.

30
00:02:27,030 --> 00:02:32,280
And if you want to stack vertically you'd want to do this there.

31
00:02:34,900 --> 00:02:40,020
And yeah, as you expected

32
00:02:40,020 --> 00:02:47,460
this will concatenate the arrays in the vertical position, in the vertical axis.

33
00:02:47,550 --> 00:02:48,340
Be aware that

34
00:02:48,390 --> 00:02:56,470
if you try to concatenate arrays that have different dimensions you'll have,

35
00:02:56,560 --> 00:02:57,610
you'll get an error.

36
00:02:57,630 --> 00:03:00,650
So Ims has three dimensions

37
00:03:00,660 --> 00:03:09,150
if you can remember that from up here. Now you learnd how to concatenate. And how both splitting an array

38
00:03:09,150 --> 00:03:11,700
into smaller arrays?

39
00:03:12,180 --> 00:03:21,440
Well to do that you could create a variable and then Numpy.horizontalsplit for splitting horizontally

40
00:03:22,310 --> 00:03:25,330
and then this expects a Numpy array.

41
00:03:25,500 --> 00:03:28,860
And how many arrays you want to produce out of that?

42
00:03:29,340 --> 00:03:35,400
So horizontally let's say 3.

43
00:03:37,310 --> 00:03:42,870
Yeah, this says array spilt does not result in an equal division.

44
00:03:42,870 --> 00:03:46,640
The reason for that is you know we're trying�

45
00:03:46,710 --> 00:03:50,170
This array has one two three four five columns.

46
00:03:50,220 --> 00:03:56,030
So you're trying to divide five with three and Numpy cannot decide how to do that.

47
00:03:56,220 --> 00:04:03,300
So should it give to you a Numpy array with this 2 columns first and then another Numpy array with two columns

48
00:04:03,660 --> 00:04:05,920
and then the last Numpy array with one column.

49
00:04:05,970 --> 00:04:08,720
So Numpy cannot do that.

50
00:04:08,810 --> 00:04:12,630
Well you should do is maybe 5 there

51
00:04:13,140 --> 00:04:15,530
and lst.

52
00:04:18,390 --> 00:04:24,930
That should give you five different Numpy arrays which in this case happens to be you know one array for

53
00:04:24,960 --> 00:04:33,930
each column and you can do vertical splitting. This time we can try three because we have nine rows there.

54
00:04:36,870 --> 00:04:41,640
And yeah, we get three small arrays.

55
00:04:42,090 --> 00:04:44,640
Note that this lst, so the split

56
00:04:44,700 --> 00:04:49,090
what it produces is Python list of Numpy arrays.

57
00:04:50,010 --> 00:04:58,210
So it's a playing Python list and out of that you can access each of the Numpy arrays if you like.

58
00:04:58,520 --> 00:05:02,770
You know that. It outputs the first arrey.

59
00:05:03,170 --> 00:05:10,020
And yeah that's about concatenating and splitting Numpy arrays. Hope I've given you a good overview of Numpy.

60
00:05:10,040 --> 00:05:10,320

61

00:05:10,740 --> 00:05:18,390
I try to do some practical examples like opening images but this is still yet in the theoretical part.

62
00:05:18,390 --> 00:05:24,730
Numpy is quite theoretical and you only understand it when you get to use it like these.

63
00:05:24,800 --> 00:05:31,080
Real world examples like working with Pandas as we did previously in the course and also working with

64
00:05:31,080 --> 00:05:32,220
images.

65
00:05:32,220 --> 00:05:35,090
So we've run into some hard core image processing

66
00:05:35,110 --> 00:05:39,190
in the next lectures, in the next session and you'll see how

67
00:05:39,180 --> 00:05:41,590
Numpy comes in handy in there.

68
00:05:41,760 --> 00:05:42,950
And yeah, I hope you enjoyed this.

69
00:05:42,960 --> 00:05:44,220
I'll see you later.

