Welcome to this section on packages.
The two packages we shall be looking at now I am apt to leave to install this.
Just have people install numpy and then to use it.
You could have simply known as and the number is a high performance computing library a see how to create
a simple nonpareil.
So we have that we have e equals and array obviously we have import it non pires mp.
So everywhere we have an empire with simple to use and the pattern array.
Let's have this one dimensional list and there we go.
We have that we could not print out.
E And that's it.
That's our an umpire.
Ray We could also define a two dimensional array a B.
And Peter Del Rey, we have this two dimensional array zero negative form then.
Six.
We could also specify the data type.
So your what is your specify the data type so you look for on that.
Let's check on this.
We're supposed to have a comma, right?
Yeah, we're on that.
Now, let's bring out B, which is a two dimensional array we see that is made of three rows and one,
two, three, four, five columns.
If you do be that ship.
See, we have three rows.
Five columns.
It's very important to always come up.
Get this ship.
Because when debugging your code, get into know a given arrays ship is very important.
Note that a simple list see like this.
If you have to print out e that ship you will have this error list has no attribute ship.
Now if you have no compiler already C that works.
Now we could print out the non pilot array which takes an A.
So this now is a non-priority which kicks in, which is basically made of this list.
But this one has the advantage that we could make use of non-price methods and properties.
We could also create a zero hour re so we have the E and the zeros and then once the a kind of array
just never specified a ship.
See, we have an error which is very common.
Make sure that you put this as a double so we should have that.
So specifying this.
We have this ship here and that's fine.
Now print out E.
And there we go.
We have this three rows and then five columns to have see it.
See the difference graph one that the.
And if you have any problem understanding the role colored notations, you could check out on our linear
algebra course.
Apart from those zeros, we could also have one.
So just like that.
There we go.
If we want to have a particular number, you can simply take five by that and all this.
So we have five times all the ones.
So that's what we get.
Yeah, 15.
And basically, that's it.
Also create an array which goes from one value to another.
So we have in space now as a word goal, we have lean space.
So we are going to go from C 3 to 9 while giving a space of two.
That's pretty not a.
You have this theory nine.
No, actually, what the what this does is similar to the arrangement as a there's a difference.
Let's take this off and then have arranged run that.
They went out.
Okay.
So this is the end, Peter.
Arrange and years and put up lane space.
For the two methods we're going from this initial position to this final position for the lean space
will define the number of.
Different values we shall take.
So since we've set out to work with only two values, we start with three and obviously we end with
nine.
So we weren't working with two values.
Now, if we go to three values, you would have another value coming up in the middle.
So here we have three, six, nine.
If you go to four values, so you have three, five, four, seven, nine.
So basically what this does is it takes nine minus three, gives us six, and it tries to break it up
or break this sequence up such that we have four different points.
Continuing reasons you have to work with decimals, so that is it.
Now we have the four range.
We are not defining the number of points which are off in our list.
So the number of elements which are have now least with this, is that what we're defining is a step
between each element.
So if we say we have a step two, so almost start three plus two, we go to five plus two, we go to
seven.
And then we don't also take in the last element.
So that's why we have this three, five, seven.
Let's modify this to say a step of one.
You see we go three, four, five, six, seven, eight, and then we don't take the last.
This two is similar to the range function where we are from C 3 to 9, 3 to 9.
And what happens if I that we want to for that let's bring this out.
See, we have 392 and we have four I in range three nine.
To keep an eye on.
There we go.
We have three, five, seven, which is similar to what we had here.
We could also create an identity matrix very easily.
Suppose we have this, we have an eye.
We have the shape, the exact five way five.
Arbiter that doesn't take that.
So let's pass this way.
Print out E so this arrow, so it means we need a partnership symbol like that.
So would I.
Instead of having to put the shape as a tuple, we just have to pass it this way.
You could pass it like this.
Simply unlike with the zeros.
Where was a zero we have here?
Where if we just have C.
That.
See, we have an arrow.
So let's get back to this.
Would I run it like that?
And then we have this idea that's a metric we'd want, and this diagonal and all the other positions
are zero.
We could also create an empty array so we could see empty that empty see through it.
We print out a.
Just like with the zeros and it specify this.
So that's it.
Then many times we shall be working with random numbers.
So it could have and be that random random C for let's let's have that C we have this random numbers.
We should generate it.
Now we could specify the shape C four or five.
There we go.
Now, we have seen many of this operations.
This method is called on a single array.
Let's suppose we define this array and with that array, let's just copy from this.
Yeah.
So we'll define this array.
That is.
Yeah, we have a, which is this.
Ah they could bring out a ship three by five.
Those if I'm B now B could be a random array, random of random.
Specify the shape C three by five two.
So that's it.
Now we have this random array, three by five, three by five and yeah, we have B, so now let's.
Let's print out E plus B.
This doesn't take shape.
So let's take that off.
Okay, that's fine now.
Or I didn't up this too.
It's just like simple matrix addition.
You see that?
Just the an element wise addition where there's elements added on to this corresponding element in the
the array and all the rest follow.
So that's it.
Now, if we had, for example, zeros here, let's say we have zeros on that and see that this area
is going to be maintained.
Because basically, I would add in this with zeros, it would say we want to once we notice we have
three plus one, four, four plus one, five, six plus one, seven, so on and so forth.
We could also.
Subtract.
So instead of this, we're going to have subtraction.
That's it.
Now, here have division C is an element.
Y is division actually.
So since this is once we would have this E maintained and then if we had, for example, zeros here
c.
We have all this in finite values because we are dividing is not a real number zero.
Now, let's let's take this to once.
I'm a girl so I have multiply so we could have run like that.
There we go multiply and is we want again maintains values element wise multiplication actually.
Now if want to do we could also do non-paid a, add a and B so do that we would do a non pilot subtract
could do non paid out divide.
We could do non paid up multiply c is the same.
Now this is all I am in wise operations and I want to do the matrix multiplication that we know and
as is actually different from this.
And then my wife's multiplication we have the met more so run that you see that we already have an error.
And the reason why we have error is because a shape is three five and then B ship is five is right 352.
Now note that I recall that when doing matrix multiplication, the number of columns of the first matrix
must be the same as the number of rows of the second matrix.
So in this case, five is now equals three.
That's why we have this error.
And so to correct this, we could say, for example, we have to define this as a the transpose of this
so that instead of having three is that you five you have a shape five three and in that case we will
see that this to be the same.
And if this two are the same, then we would have an output of shape three three.
So now let's run this and see that it works fine.
So output associated with three then our matrix multiplication on that.
If we do multi multiply see we have an error because the element why is multiplication going to what?
When the two then have exactly the same shape?
No problem.
Then the transpose is the way we could define empty, not transpose.
That's it.
We're on that.
Obviously now we need to do multiplication or metric multiplication.
That's fine.
There are also many common functions which come up, which are which come with no empire, which we
could use.
Like, for example, if we have e this number E, we could have E that some.
There we go.
We have a 9 to 5 telling us that the sum of all these elements equals nine of five.
We could actually see, for example, let's, let's define E to be equals and be the ones of C for two.
So in this case, we will have a different position.
So the sum should give us it from that c we have a sum of eight for the minimum value.
That should be one for the maximum value that should be one.
We look for the mean, for the mean.
Look for the standard deviation.
We could also do some sorting.
So we have start that's printed out either Saad.
All this actually does a story.
And so that's after doing the story and we can now print out, actually.
So that's it.
Now let's define.
Let's say we have this.
Let's take this off.
Let's say we have this in that array for one zero.
Negative four.
Yeah, that's fine.
Now that's sorted and then print it out.
So after sorting, we see that is actually we saw that.
And also, instead of doing this way, we could just directly print out and P that sort of E so we run
that.
On that basis.
Greg saw that.
Now he could also use an axe art.
What is actually art?
Let's just bring out the sword.
And Peter saw a.
And then.
Okay, that's.
That's the accent.
The sort of accent.
Okay, let's run that away.
So now we've done the sergeant.
What I start does is it actually looks at the positions or the position that is negative for occupied
initially.
So like after Sgt, we see that the negative four comes to the first position.
So we see that the first position we're putting out, the three, the three symbolises
this.
All of the sudden the first position will be occupied by the value which initially was on the third
position.
And then the all zero position is 00123.
So the zero position will be occupied by the value which was initially on the third position, zero
one, two, three, negative four, that's it.
And then here this first position will be occupied by the value which was initially on the second position
012.
That's why we have that zero.
It was initially the second position.
So that's how we look at it with an ax.
So it will look at your previous position, which is start.
We actually look at you all, we actually look at a number, all the element in question and the very
important matter is the shape.
So let's, let's come back to this, let's use this.
So suppose that we have this array of printed it already the shape three five and then we want to reshape
this to say five three or we could have years and the the shape of a.
And then we specify the ship.
So specify the new ship, one new ship to be five three.
One wanted to go from three five, two, five, three.
There's no cute shape to off and that's it.
Now that's putting out the shape of this new.
So we have your five to we now know that if we see for example one to have a new shape five four as
you give us an arrow and this is normal because.
First of all, this initial array of dimension of shape three five has 15 different positions.
One, two, three, four, five, then three units, 15 positions, whereas this new array has any position.
So it's not possible that we do a reshape so that it will be a match between this initial array and
its reshaped array.
So that's why that doesn't work.
We have to rerun that.
We see that we now have three, four, six as a first row, three, four, six.
You're just like the first row, then zero, -1 to 6.
And as it follows that we could also see a one negative one.
Now we put negative one.
What this what happens here is number two is going to automatically get this value for you so many times
when we want to carry out this kind of operations, put in a negative one, it just says we give number
the liberty to tell us what value is best for us here.
So if we do this so it gives us the answer.
We know that shape.
That's it.
Now, if we had instead of that, if we had three, that's not going to be let's not take three.
Suppose we had oh, let's add this to this perform three, this and all the value of this.
If you put three, this is going to give you a five.
Exactly.
The model for you.
If you put C two, no matter where you put your C, you must have an error because obviously having
two means we're going to have an even number of possibilities or number of elements.
And yeah, already we have an odd number, so it's not possible.
Now we reshape this into an even number.
Pick that back.
That's fine.
Another matter is the concatenate method.
So suppose we have this.
Yeah.
Let's make it simple.
We have your four and then we have the B and beta array with six and maybe just five.
Now we could have NP concatenate and B from that let's modify this, put it to pull.
That's fine.
Now run it.
And there we go.
We'll see how we concatenate this.
We have six, five, four, and then this is added on it.
Now let's specify the axis like normally would by default as axis is zero.
Now seen that zero simply means let's take this aid and see.
Okay.
By saying as zero simply means the concatenation of this to arrays is done on the zero axis.
Which in this case is the loan axis.
Now in this kind of area, this to the area right here, we do not have just one axis.
Let's bring this twice.
We have the A and B.
Now, let's take of some of those elements.
We have three, 3 to 2.
So it's a three by two array that we have four be and this is five by three, we could bring this out.
So we have a shape.
She brings me that --.
There we go.
Three, five, three, two.
Now let's do the concatenation and see what we get.
Now the and be that concatenated of A and B now by default as the set, if we don't specify the axis
that the default axis is zero.
So let's run this.
We have this error, which is normal.
Now let's understand what's going on.
When doing condemnation.
What goes on is that the axis like in this case, the axis is actually zero.
So even if we do axis equals zero, we'll still have this error because by default axis had two zero.
So when doing a combination, as we're saying here, we have this axis always specifying axis zero.
So what goes on is this two are somehow fixed.
And then what Nompu tries to check now is to ensure that the other axis are the same.
So if we want to concatenate this to O on the zero axis, then we fix the zero axis as Yeah, we'll
fix this, we fix this, and then we verify if this two are the same.
If they're not the same, then we cannot do the concatenation.
So just like with this, when we fix the zero axis, we see that actually it doesn't alter axis.
So we could simply the coordination was possible, but here where the axis where we have this first
axis and this first axis, here they are both different.
So we cannot the combination cannot be done.
Now, another way of looking at this is by saying that if you have this array, the shape is given as
the row and the column.
So if you have an array, the shape is a row column.
Now, if by default the axis is zero, it means you are doing concatenation across the row.
Now, if you look at those rows here, we are having to concatenate this row with this auto one.
And to do this, does the number of elements we have here must match up with the number of elements
we have here?
Same with this.
You see, we want to continue this to the two elements.
Our number of elements must match with this.
Our example here, we have actually no row and no column because this is one dimensional.
And since this is one dimensional, we could just simply use pack this or add this to the end right
here.
But now we're dealing with a two dimensional array.
We have to be very careful with the way we do the cook up the nations.
So, yeah, this kind of cannot be concatenated on this.
This two can be concatenated and this too.
Now, we want this to actually work.
We must ensure that for a given axis while fixing, like if we work with the first axis as we fix this
and we fix this, the other axis must be the same.
So in this case, for example, we see that there is a must three.
So this should work.
Now looking at this and then now we will see that if we are to coordinate this two to the columns,
then we will have three 5 to 6 zero, which is going to be added here and then 440 added again.
So let's run this.
So you can see that clearly.
We have 3460, negative one is four and we have this 34260 which is added this line here and then we
have 440, which is added.
So yeah, we concatenate this array with this auto one.
Now let's go ahead and modify this again.
Suppose we have now two.
So let's come like this.
Now we have to run it.
See, we have an error to go to zero.
We'll see.
I have an error.
It's impossible to do the concatenation.
So to do a concatenation, the axis we select is fixed and we monitor the order axis to be sure that
the concatenation possible.
Also, apart from the two, the arrays and the one the arrays, we could also define three dimensional
arrays.
Let's copy this.
He's out.
Yeah.
Now, if I defined a three dimensional array, then we'll need an axis.
So let's put it this way.
This is like this is seen as regrouping two dimensional arrays, as you could see, with a two dimensional
array where a group in this one, the area is this one is one and this one and they are seen as columns
or rather just seen as rows here.
This is one row, one row and a row row.
But with three the arrays, this to the array is going to be seen as one line in our territory.
So like this we add that that we go this out to the array.
So we have this to the area right here and then let's copy this again.
So that was the first line.
The next line.
So this our first line to the next line to the just I would add to the array we had this line one the
one the one the for the one day we had just an element, an element, an element going to the to the
to the three.
Do we have to the to the.
And so without this.
There we go.
So now we have this.
One, two, three, four, five, six.
Stop there.
That's fine.
So now we have this.
And then we could close it up.
Right?
Yeah.
Split up.
Yeah.
So we could close it up there.
And that's fine.
So now we've defined this.
Let's.
Let's have that.
Okay, so we define our three d array in our the shape.
See now looking at this, we have one, two, three, four, five, six, and then for each of this,
so we should have six.
And then for each of the six, we have, uh, one, two, three, five, six, three, five.
This command is out of shape.
There we go.
We have six three, five, three knows that we have six different three by five to the Aries again.
Yeah.
If we have to do concatenation, suppose we have let's take this for example, this, this, this,
we use this.
I will bring this out.
Take this.
Yeah.
We're B and then we take just two of this.
Okay, so we have just 12 this.
We could print out each bishop, so we have b the --.
There we go.
Two, three, five, six, three, five.
Now, as you could see here, if we're in a combination so we could print out.
And B, that concatenate of a B now in this case is going to work because if by default the axis is
zero, the axis of zero by default amounts.
We are fixing this and fixing this.
Then we are going to look at the other part.
So we have look at is to the array and compare it with the dimension of this to the array.
So if the ship is the same as the ship, then the concatenation is possible like in this case.
So could run that.
Yeah.
This arrow presupposes probably.
And that's fine.
Now we have this.
We could monitor, monetize ship.
So we have to shape the social partnership before.
So we have this, okay, we have it by three by five.
So the coordination has been done on this zero axis.
Now, if you have to do that on the first axis, so we have x equals one.
You see, normally that shouldn't work because fixing this axis, the six five doesn't match with two
five.
So that wouldn't work.
Now, if we have to do on the second axis, it should work too, because fixing this six three doesn't
match with two three.
But then if we take this off.
So if we take some of this off, let's take this off on that run.
It works.
Because when we fix this second axis to three matches with two three, so that's fine.
Now, even if we don't have five elements, or even if we have C for this one, we could have C four
elements.
Four, four, four, four.
Run it.
C, we have four elements.
For each of this to the race.
So we have four columns for each editorial race.
Now, if we fix that second act, this is still going to work.
Yeah.
We have this area because the axis here was zero.
Now, let's let's have this axis equals to see that works fine.
The shape is two, three, nine.
We've fixed the second and then we'll compare this first two axis that same.
So the combination is possible.
Now also, when given an array, say we given this array, let's take this to the area.
When given this kind of array, we could get specific elements depending on your positions.
So if we have this a we could say we want to get e zero now a0 corresponds to the zeroth row.
So that's the correspond to this.
Right.
And you see we have 3460 negative one.
Now if 11c works we want to we have this last one don't we should try an arrow.
So because we actually have three rows so we should go from zero one, which we have zero one and two.
So that's it.
Now if you want to be more specific, we could have one and then zero, meaning that we're going the
zero one that's first row and then the zero column.
So that's 56 and that's it.
We have 56 if we select three, so we can have six.
So like it we have an arrow.
So have this 30101236.
So right we have a six year easy way of doing this is by using the comma.
So we have one comma, three, the first row and the third column.
So we have the same answer also using the same command notation we could have or we could select the
first row, for example.
Now so the first rule was selecting all the elements in the columns we could use the column by in column
we just simply saying in all.
So basically this is equal to saying all columns.
Now the columns obviously are different from the columns.
So we have that columns.
So we have in one that C we have 56.
That's the first row.
The Yeah.
The first row there's is zero it row, first row, second row.
Now we could pick out a second C basically what we're saying is take the second row and all those columns.
Now if we say zero it means take the second row and the zeroth column.
So second row zero column will restrict only this value.
That's why you see we have just one value, so we'll do that.
That's fine.
Now we could also decide to work with only the columns.
So we have that.
Let's say we have four now we have in all the rows, but only the fourth column.
So we go zero one, two, three, four.
That's actually the last column on that.
So we have negative one six two, negative one six two.
Let's not philippines's out of spin out e so it appears looks better now is it negative one six two.
That's fine.
We could do some slides in with slides and let's take this one the array.
They did put it out.
Yeah.
Now let's increase the 612169, eight.
That's fine.
Now print out the E.
But now we actually slice it out so we could see want to work from one right up to four.
So you go zero one as it.
Two, three, four, two, go.
Five, four, six, one.
But in this notation, what is saying is go from the start to the index minus one.
So that's why we have four.
We have five, we have four, we have six, but we don't take one into consideration, although normally
this is like zero.
One.
Two.
Three.
Take that.
Three.
Yeah.
Four and five and then the rest.
So yeah, we have in one, two, 4 minutes we're taking this one, two, four, but we're not taking
the last index.
So we just in a year and this corresponds to five, four, six.
That's it.
We could also do 0 to 4.
See, we have come on that.
So we have six now.
We have all this zero to see nine.
There we go.
Then we could see we want to take all the first nine elements.
So instead of specifying zero, we just do that.
And it starts from the zero position.
Now, if we want to go from a given position to the last position, we just do that.
And it is from four as second for six 1 to 1, six, nine, eight and as it must be, not a.
So we see that clearly.
So that's it.
We actually take this for.
We could do this five C matches up with the first five elements.
Then if we do a negative one.
What we're saying here is start from the first elements and go right up to the.
Last now grown ups, a lot of similar means.
We're going to go around the last minus one index.
That's why we have this year.
If you want to have minus two.
So you would go out to the last but one index.
So we actually end up your businesses index one one, we end up now with this.
So we go from six, five, four, six, one, two, one in about 600 business.
Now I'm putting this to the array.
Wrong again.
You see, we, there's, there's the greens.
So now we have this to the area e we taken all the elements.
Let's say we take all the elements from the, we take the first element of the second elements is basically
saying we're taking the.
First row with the goal of taking the zero at row.
We're taking the first row and that's it.
That way we have this rule and then this row.
We don't take this one because we're going out to index minus one or just an index minus one.
Now.
We haven't that we've seen that clearly.
We could now have see zero or could see one to the end.
I would just have to say we have towards the end, see, we take this only now we can have one, two
and think that we could have all that's fine is the same with how it is obviously so that we will have
all the rows, but now we decide to pick the columns so we could to go from 2 to 3.
See that.
Good thing for.
Let's see for that.
Run it.
Okay.
Now, what we're doing here is we've seen for the roles, take all the rules, work with all the rules
of work with this role.
The role on this role before the columns work with the second column, I work with the from the second
column to the foot column.
And obviously, since we're going up to index one as one, we're working with the second column and
the third column does two and three.
So when I including four.
So that's why we go zero.
Let's see, we go zero, one to second and then the third, this, that's fine.
So we have 605631 and that's what we got here.
This is similar to doing this.
We're going to have C one, two, two and then take all the columns on that.
C we have that.
Yeah.
We're picking out the.
First all take zero.
We don't take zero.
Actually the one we only end we end there because we're going up to two.
So just after and we could always take three.
So now we could take the second.
Yeah.
With the second row zero four is and second.
So we have one two before across all the columns.
We could also go ahead and specify that we want to take the.
First to Cullen.
So good.
I have to have that like that.
So we have the one on two for the roles role one and two.
So we have this role and this role and in this role, one and two, we have the first two columns.
So we have this let's take from this we have role one, rule two for the columns we have up to the second.
So we go zero one to.
Now that we know that in this last index we'll go from zero or one and then it will be in 1 to 3.
We have in the first on the second row, it was the first on the second.
And then in this first and second, we're picking out the zero and the first column.
So we have zero and first intersection happens to be the fifth 26400.
And this we have the fifth 26400.
Now, we could also see if we want to have all this.
Yeah.
Can run it like that.
We pick out the first one, three for the rows and then we have all the columns.
Apart from doing this, we could use three dots.
The three dots simply means take all four, all the remaining axes.
Now that we have just one axis here, that's ones that pick out this row axis will have one over the
column axis.
So basically we just have one axis year remaining.
So within that take of the all the remaining axis so that we can have the same results.
Now let's work with 3D input.
Let's come to.
You had this tree, okay?
We had our 3-D input.
Yeah.
We take this off?
Take that off.
We have a and now we've seen this.
Let's take this awesome New Year's.
Yeah, that's it.
So we have this here we this off to on that for now.
Let's let's just have this.
So for now we we have in the.
First as we go from one of the three that E is e.
So as cause this was a logistics of so it could be better.
So aid is a and then there is this selected or sliced version of E and there's a version.
What we're doing is we're taking out giving that a let's look at a ship that's not a ship.
So it's clear ship.
In this version, we're working with the first and the second axis for this first dimension where we
have the first dimension, the second and the third dimension.
So we were working with the first and the second axis, obviously, because we're going to go up to
index, we go up to index minus one.
And so if you look at this, you're working with the first and second symbol means this is the zero,
then this is the first.
So we're working with this and clearly this is the output we get.
Now if after picking out this output, we want to get more specific.
So we want to get the zero output.
So after picking this out, we want to get a zero up.
We could have zero run it again.
There we go.
We have this 3460 negative one.
So after picking out this first.
We take the zero that is now the the zero row year 0123 you want to take the first two have zero up
to one.
No up to two because we have zero and want to run that.
See we have this and this.
Now we could also pick that obviously pick from the beginning.
So from the beginning here you see that with this we pick all this, we pick this one zero and then
we also pick one.
That's the essence of this.
Then in this for this specific one, we pick the zero up to two.
So that's why we have zero and one.
That's it.
Yeah.
For the next one, we also p zero and one.
Now if we have just one, you see, it just does zero.
GOP does zero.
If we take this to the one C we pick now just one because we pick it out in the Xs, the first Xs for
the 000 Xs.
We're picking the values from 1 to 3.
So yeah, we started, we went over to take this zero Xs.
We're going to start with one.
And then in this one we are going to work from 0 to 1 again.
So we just pick out just this one.
Now, if we get this one, we want to pick out a given element.
We could say we want to pick out see the second element.
So we'll pick out this and then we go zero one, two over six and as soon as we have six now, we could
also pick out a slice in this.
So it could go from 2 to 4.
So 01226060.
Now forgetting that we could obviously put this swamping all we can arguments we're working with all
the different columns now we could also use the three dots gives the same answer.
Another interesting work with two years and the kids will want to do this.
Let's say we want to have this all of this implements all of this.
So we pick only the first axis.
I just do this.
Let's have this.
We be to the first axis.
I could pick only the zero axis, which is now this doesn't make a difference.
Let's say we have 41 and then so you see that difference now.
So here we pick out the zeros and then four for the zero we pick now.
All the rows and then all the columns.
That's why we have all this year.
Odds are we print it out now.
If we want to do this simply, we could also have three dots.
Now, just three does, as we said, means for the rest of the axis to everything.
So it is going to have the same.