1
00:00:00,060 --> 00:00:06,000
So in the previous lecture, we have learned about lists, and I told you that lists are nice for storing

2
00:00:06,270 --> 00:00:13,290
some small amount of numbers or strings and for which we don't want to do any further mathematical calculations.

3
00:00:13,890 --> 00:00:19,230
However, if we want to do mathematical calculations, which we will do a lot in this course, we will

4
00:00:19,230 --> 00:00:19,770
have to use.

5
00:00:19,770 --> 00:00:24,870
Arrays and arrays are not natively implemented in Python.

6
00:00:25,380 --> 00:00:27,870
They are implemented in a module called Nampai.

7
00:00:28,650 --> 00:00:32,439
So if you followed the previous lectures, we have already imported this.

8
00:00:32,460 --> 00:00:34,470
So let me scroll up to the very top.

9
00:00:34,860 --> 00:00:44,610
We have imported Nampai, S and P, and we need this to be able to use arrays because to define an array,

10
00:00:44,640 --> 00:00:50,070
what we have to write is, for example, let me stored in the variable called array one.

11
00:00:50,550 --> 00:00:52,800
We right and p dot array.

12
00:00:53,610 --> 00:00:56,010
And then the syntax is normal brackets.

13
00:00:56,550 --> 00:01:02,370
And then here we can write the square brackets one for nine, for example.

14
00:01:03,090 --> 00:01:04,280
This would be our right.

15
00:01:05,430 --> 00:01:08,670
So of course, let me call this.

16
00:01:09,420 --> 00:01:13,920
So you see, the result would be an array which has these numbers.

17
00:01:15,060 --> 00:01:18,000
So you may wonder, why do we have these double brackets here?

18
00:01:18,480 --> 00:01:24,720
And the reason for this is that we also can define multidimensional arrays.

19
00:01:25,470 --> 00:01:30,270
So let's redefine the two lists that we have defined previously also as arrays.

20
00:01:30,480 --> 00:01:34,110
So we had here one, a three.

21
00:01:35,160 --> 00:01:39,630
And here we had two lists that emerged inside each other.

22
00:01:39,640 --> 00:01:44,190
So the first one one one two three and a second one was

23
00:01:47,370 --> 00:01:49,650
this was one four nine.

24
00:01:51,210 --> 00:01:56,820
Now you can see how the syntax works, so we need the normal brackets, basically.

25
00:01:57,240 --> 00:02:01,140
Yeah, it's it's related to the NPRA commands.

26
00:02:01,500 --> 00:02:05,670
And then here we have these two lists, you could say that emerged.

27
00:02:05,670 --> 00:02:08,470
But since we have right here array, there are not lists anymore.

28
00:02:08,490 --> 00:02:09,660
Now they are arrays.

29
00:02:10,229 --> 00:02:12,750
We can call them, for example, like this.

30
00:02:12,750 --> 00:02:16,440
And you see, this is already nicely organized in the output.

31
00:02:16,740 --> 00:02:19,650
And it looks like a matrix from mathematics.

32
00:02:21,270 --> 00:02:27,210
So, of course, we can now select individual elements like we did for lists so we can write every one

33
00:02:28,020 --> 00:02:33,540
square bracket, one which gives us the second element since we're again start counting from zero.

34
00:02:34,620 --> 00:02:38,340
And we can also select multiple of these.

35
00:02:38,350 --> 00:02:43,050
So if we want to have the first two elements done, we get these two.

36
00:02:43,590 --> 00:02:47,820
And here you realize if we just select a single number, then it's just a number.

37
00:02:48,000 --> 00:02:54,030
And if we select multiple numbers, then it will remain the property of the array so that data type

38
00:02:54,540 --> 00:02:55,410
will be on the right.

39
00:02:57,510 --> 00:03:05,880
So if we do this for the second array, which would give us one as a number and a as a string, we have

40
00:03:05,880 --> 00:03:07,080
two different data types.

41
00:03:08,160 --> 00:03:14,700
This works, but gives us as an output, another option or property, which means something like a mixed

42
00:03:14,700 --> 00:03:15,360
data type.

43
00:03:17,080 --> 00:03:22,000
Now, if we want to select elements of a multi-dimensional array, which would, in our case, be the

44
00:03:22,000 --> 00:03:26,950
array number three, this one here, then we can of course do this.

45
00:03:27,310 --> 00:03:34,960
For example, if we want to have this property here, so we have to write zero and then to.

46
00:03:37,340 --> 00:03:43,490
But so this is exactly the same as for this, but since we now have an array, we can also make it more

47
00:03:43,490 --> 00:03:48,110
easy and just right like this is what exactly the same result.

48
00:03:49,730 --> 00:03:56,480
So manipulating arrays is, of course, somewhat similar to this, but there are also important differences.

49
00:03:58,390 --> 00:04:03,760
So there you cannot use anymore the syntax that we had previously.

50
00:04:03,790 --> 00:04:04,660
Let me scroll up.

51
00:04:05,440 --> 00:04:13,150
So we have previously list Dot Append, which is something that just works for lists that are natively

52
00:04:13,150 --> 00:04:14,560
implemented in Python.

53
00:04:15,520 --> 00:04:22,240
So here we must use a different commands and this command is called Nampai Dot Prepend.

54
00:04:23,590 --> 00:04:29,620
So if we just use this command, Python doesn't know which area we want to manipulate.

55
00:04:29,860 --> 00:04:36,250
So first, we must start with the array that we want to manipulate, and then we write a comma.

56
00:04:36,490 --> 00:04:37,780
And the thing we want to add.

57
00:04:39,070 --> 00:04:40,810
So this will be the new array.

58
00:04:42,010 --> 00:04:46,930
But there's another important difference here previously for the lists, if we would write something

59
00:04:46,930 --> 00:04:47,500
similar.

60
00:04:48,010 --> 00:04:52,810
Then the list would now have been updated already here.

61
00:04:52,840 --> 00:04:53,740
This is not the case.

62
00:04:54,340 --> 00:04:57,970
If we right now, everyone, the old area appears.

63
00:04:58,510 --> 00:05:02,170
This is because here we do not have lists anymore, but we have no idea.

64
00:05:03,610 --> 00:05:10,360
So if we want to update the array, what we have to do is then write every one equals.

65
00:05:12,140 --> 00:05:14,960
This one and now.

66
00:05:18,990 --> 00:05:21,330
Sorry, I somehow switched to data time, I think.

67
00:05:23,550 --> 00:05:23,880
Yes.

68
00:05:24,390 --> 00:05:34,020
So now the one is updated, so of course, we can also use this append commands here for more general

69
00:05:34,020 --> 00:05:34,650
purposes.

70
00:05:35,010 --> 00:05:41,550
So, for example, we could now add to your true numbers at the same time, and we could do this by

71
00:05:41,550 --> 00:05:45,060
adding or by appending voucher to see a whole array.

72
00:05:45,060 --> 00:05:48,780
So we write and pray no more brackets.

73
00:05:49,020 --> 00:05:52,690
Square brackets 5.6 now.

74
00:05:53,900 --> 00:05:55,680
Oh, I did the same mistake again.

75
00:05:56,970 --> 00:06:00,120
No one will be this.

76
00:06:00,180 --> 00:06:04,710
So we have this hour and we have appended these two numbers.

77
00:06:06,830 --> 00:06:12,380
So what we can also do is we can, of course, manipulate multidimensional areas.

78
00:06:12,980 --> 00:06:17,630
So let's get back to our error number three, which is this matrix.

79
00:06:18,170 --> 00:06:22,270
So basically, we have two arrays stored inside of one array.

80
00:06:23,240 --> 00:06:31,370
So what we can do now is we can also append here some numbers or some errors so we can write and we

81
00:06:32,930 --> 00:06:41,480
don't depend on a three comma and we right here what we want to append.

82
00:06:41,480 --> 00:06:49,790
So it just will again be an array and the array will, for example, be one eight twenty seven, which

83
00:06:49,790 --> 00:06:51,410
will be the cubic numbers of these.

84
00:06:52,310 --> 00:06:53,600
So what happens if we run this?

85
00:06:54,860 --> 00:06:57,410
Oh, this, this doesn't give us what we want.

86
00:06:57,890 --> 00:07:03,650
It gives us one two three one four nine one eight twenty seven as a single one dimensional already.

87
00:07:05,270 --> 00:07:09,230
So what I wanted to do here is add another line.

88
00:07:10,250 --> 00:07:14,360
So in order to do this, we must use a bit of a different syntax.

89
00:07:15,320 --> 00:07:17,930
So let me copy this and no change it.

90
00:07:18,680 --> 00:07:26,810
So you see, the array number three starts with two square brackets, so we must now also start with

91
00:07:26,810 --> 00:07:30,440
two square brackets so that these two arrays have the same rank.

92
00:07:31,790 --> 00:07:33,920
And now it will still not work.

93
00:07:35,210 --> 00:07:38,630
Still give the same result that we do not really want.

94
00:07:39,020 --> 00:07:46,430
So we must tell it and option an additional property how we want to merge these two lists, or how we

95
00:07:46,430 --> 00:07:51,170
want to append the array here to the other array.

96
00:07:51,290 --> 00:08:00,650
And this will be axis equals zero, which means basically add or append this array on the first level.

97
00:08:01,040 --> 00:08:08,510
So see row once again since first start counting from zero means first level, and then we will get

98
00:08:08,510 --> 00:08:10,250
this nice three by three matrix.

99
00:08:11,660 --> 00:08:16,550
Of course, we could also do this differently.

100
00:08:17,780 --> 00:08:22,460
We could do this by adding a different row here instead.

101
00:08:23,090 --> 00:08:28,760
For this, we would have to, for example, overwrite four and 16.

102
00:08:30,140 --> 00:08:38,919
And now I think we have to right access one, which would be the second level on the way yet in horror.

103
00:08:38,960 --> 00:08:41,030
Let me check what's the problem here?

104
00:08:41,510 --> 00:08:42,610
Oh, yeah, right?

105
00:08:42,620 --> 00:08:53,480
Because basically, if you see we want to add it here, so we must have here these these square brackets

106
00:08:53,480 --> 00:08:53,900
as well.

107
00:08:54,440 --> 00:08:56,750
So like this?

108
00:08:57,710 --> 00:09:04,970
OK, so you see, manipulating multidimensional arrays can be a bit tricky because you have to really

109
00:09:04,970 --> 00:09:06,950
take care of the syntax.

110
00:09:07,640 --> 00:09:13,550
So you do not only need these arguments axis one and axis zero, but also you need to make sure that

111
00:09:13,550 --> 00:09:15,320
these brackets here are correct.

112
00:09:16,940 --> 00:09:19,060
By the way, I messed up here a bit.

113
00:09:19,070 --> 00:09:21,170
This is, of course, not supposed to be math.

114
00:09:21,170 --> 00:09:26,000
Is this supposed to be manipulated so we can just click here and move this to the bottom?

115
00:09:27,350 --> 00:09:27,670
Yeah.

116
00:09:27,680 --> 00:09:28,940
So now let's come to math.

117
00:09:28,940 --> 00:09:30,110
This is just really quick.

118
00:09:30,290 --> 00:09:36,200
This is where I want to show you where arrays are better than lists or more simple, so we can just

119
00:09:36,200 --> 00:09:38,660
write, for example, here everyone times two.

120
00:09:39,890 --> 00:09:45,920
And if you remember what everyone was, everyone.

121
00:09:48,450 --> 00:09:50,790
Than this was one four, nine five five six.

122
00:09:51,240 --> 00:09:58,440
And now we do not just repeat this error twice, but we really multiply every element of the array by

123
00:09:58,440 --> 00:09:58,920
a number.

124
00:09:59,730 --> 00:10:02,040
So this is really useful in a mathematical way.

125
00:10:02,460 --> 00:10:05,190
And this was not possible for lists, if you remember.

126
00:10:05,580 --> 00:10:08,490
So here was the same thing for lists.

127
00:10:08,820 --> 00:10:13,350
So we had one three, four 10 and we got one three four 10 one three four 10.

128
00:10:15,340 --> 00:10:20,110
So, of course, this also works with an addition, so we could write something like this.

129
00:10:20,560 --> 00:10:24,460
So this time, every element will be added by the number two.

130
00:10:25,150 --> 00:10:27,970
And of course, it also works with multidimensional arrays

131
00:10:30,700 --> 00:10:35,080
with the multiplication and addition and also, of course, other operations.

132
00:10:36,370 --> 00:10:39,880
So I hope you see that arrays can be quite advantageous.

133
00:10:39,910 --> 00:10:45,220
So once again, this is useful when we want to do mathematical operations, sometimes we use arrays

134
00:10:45,220 --> 00:10:46,180
instead of lists.

135
00:10:46,660 --> 00:10:54,040
And also, these arrays require much less storage to store the individual elements compared to the lists.

