Alright alright alright.
So in the previous few videos we've had a look at different ways of creating an empire raise.
We've seen how we can view them.
Now let's figure out the fun part.
Let's figure out how we can manipulate and compare our different arrays.
This is where the crux of machine learning happens right.
It's manipulating performing calculations finding patterns in arrays of different numbers.
Let's start it off.
We'll put in another heading because we're keeping our notebooks nice and neat manipulating and comparing
have I spelt it right.
I usually get typos in these headings manipulating and comparing arrays.
Beautiful.
We're gonna put a little subheading here because like pandas with NUM pi if you can think of a way of
manipulating numbers you can probably do it.
So the first one we're going to look at is our riff Medtech.
Here we go lucky encoding is a little bit better than my spelling ability but arithmetic is a fancy
word for basic math equations.
So let's have a look.
Start off by checking out our A1 array.
We created this earlier A1.
Wonderful.
We'll create another one called ones actually.
We've already got ones yeah beautiful.
But if you wanted to recreate it we'll go NDP dot one's three just to make sure we know what it looks
like.
One's wonderful Okay so we're going to have a look at is nice and simple plus.
So what do you think this will do if we go A1 which is our right here plus ones.
Well let's not talk about it Daniel.
Let's run the code beautiful A1 plus once so we've got one plus one equals two two plus one equals three
three plus one equals four.
Excellent.
So all this is done has just added together the different elements in the same position of both arrays.
So the zero position one plus one it goes to the first position two plus one equals three.
And the second position is three plus one equals four.
All right well let's keep going.
Let's see a few more options.
Hey one minus one's Can you guess what'll happen here.
Zero one two three.
So all it's done is it subtracted ones from a one let's push forward let's try multiply i1 times ones
Yeah well that makes sense because our one's array is just all ones and it's just times a one by one
one times one is one one times two is two and so on.
Let's bring another array a two.
Here we go.
Now this will be interesting if we multiply A1 by A2 what's going to happen huh let's see.
Let's work through this.
So we've got one.
This is let's get up.
I won again so we can see everything in one place.
I won one times one is one two times two is four three times three point three is nine point nine.
That makes sense.
What about this second row here.
Let's see if we can figure this out by looking at it 1 4 4 2 2 5 10.
Yep three times six point five is nineteen point five.
Let's use python to help us out for that six point five.
It's nineteen point five huh.
We can get rid of this cell we don't want that actually.
Never use a toolbar escape X to get rid of that.
So what this is done is it's taken a one these three numbers here multiplied it by this row.
Put it in here and then done the same thing again with a one and multiply it by this row.
Huh that's interesting.
Let's have a look at our other array first A3 let's combine these two a two and a three a two times
a three operations could not be broadcast together with shapes two three two three three operations
could not be broadcast together.
That's interesting.
But remember right at the start the concept video where we talked about where num pi is fast because
it vector rises code through a technique called broadcasting.
Well this is what's happening here.
But to be that fast broadcasting has a few rules so let's look that up.
Num pi broadcasting.
There we go.
We're gonna go to the documentation broadcasting num pi click on that the term broadcasting describes
how num pi treats arrays with different shapes during arithmetic operations which is exactly what we're
doing.
We're trying to use some arithmetic on arrays with different shapes so there's a three and there's a
two they've got different shapes and that's what the errors coming up.
So let's have a look here.
Subject to certain constraints the smaller array is broadcast across the larger array.
So they have compatible shapes.
Well that explains what's happened up here with a one times eight to the smaller array is broadcast
across the larger array.
So they have compatible shapes that makes sense because we've got here this is a smaller array.
It's been broadcast across this row and then across this row.
So that the output has a compatible shape of the larger array.
Okay.
We'll keep going there's some examples here.
So these are two arrays multiplied.
They've got the same shape.
1 2 3 2 2 2 8 times P is one times two is two.
Two times two is four three times two is six.
Aha.
That makes sense.
And then broadcasting rule relaxes this constraint when the array shape meet certain constraints.
Okay.
So this is good.
This is the kind of workflow you want to start getting into right is if you come across an area like
this and you will all the time one of these mismatch shapes errors like different shapes that are incompatible
with each other a value area.
These are gonna come up all the time in machine learning and part of being a data scientist or a machine
learning engineer is reading documentation like we're doing now and trying to figure out how to fix
our problem.
So General broadcasting rules okay.
When operating on two arrays none pi compares their shapes.
Element wise it starts with the trailing dimensions and works that way forward two dimensions are compatible
when they are equal or one of them is one.
Now to save a little bit of time instead of going through the entire documentation I'll leave that for
you.
I want you to have a think about try and figure out a way how would we get these two to be of compatibility.
How would we fulfill this broadcasting need.
So what you may want to look into is how can you reshape A2 to be compatible with A3.
So that might be looking at search put in another comment here how to reshape num pie array.
So check out the broadcasting documentation along with searching something like this and then figure
out how to make these two shapes align.
If you can't.
That's entirely fine.
This takes a bit of practice but we're going to see how to do it in a future video.
Right now we're going to continue with our arithmetic just to finish things off.
So where were we we've done multiplication.
Let's try A1 divided by ones.
So this little slashes four divided by you can probably predict what's going to happen here.
Beautiful it works fine because our rays are similar shapes.
Okay let's try a two.
Let's try some floor division think two divided by a one.
Wonderful.
But we'll see what non floor division works here.
There we go.
So floor division what this means if you do two slashes you might have seen this in Python.
If not that's fine.
Floor division removes the decimals so you can see here it rounds it down rounds down so one point zero
point zero point zero one point one but that's been rounded down to one two point 1 6 6 6 6 7 has been
rounded down to 2.
Let's keep going.
What have we missed out on.
Let's go square a two square two.
This is a power so to the power of so everything in here is going to be to the power of two.
So if we look at a two on its own it's gonna be one times one two times two is four one times one is
one three point three times three point three is ten point eight nine will confirm that with Python
wonderful ten point eight nine that's just filled in then rounded it off actually num Pi has a square
you can use with this so all of these functions that you see here that we've gone through arithmetic
floor division etc num Pi has the equivalent here now which one should you use.
Well it's going to depend on what your workflow is best at.
So if you want to use the maths symbol operations you can use that or if you want to use Square or you
can even go and he'd add gonna go shift tab to figure out what it does it's figure out here doc string
adds arguments element wise let's try that a1 ones same as just doing a one plus ones wonderful.
I got a couple more.
I won modulo.
This is gonna show us the remainders.
So A1 divided by two let's see where that goes.
A1 divided by two let's go now in PI modulo
model.
There we go.
Return element y's remainder of division.
Wonderful.
So this is again I'm trying to exemplify the kind of workflow you go towards if you're not sure what
something does.
You can always look up the documentation and have a look.
That's what we did with broadcasting.
We've just done that with modulo if we divided every element in a one modulo two it's gonna show us
the remainder that's left over.
So let's do a two modulo two.
So this is just showing us the remainder of what's left after we've divided everything by two and if
you wanted the exponential you're not sure what this is.
Don't worry for now it's just to highlight the kind of arithmetic that you can do and num pi is gonna
take the exponential of everything in an array and if you want the log you might see this come up in
future projects of an array you can use MP dot log so that was a bit of a whirlwind tour of some of
the arithmetic functions that you can do a num pi remember if you can't imagine it.
You can probably do it.
This is only just scratching the surface.
So before next video have a practice around creating some of your own arrays and then using some of
these arithmetic functions on them.
Remember.
If in doubt run the code if you're not sure what something does.
Have a look at the NUM pi documentation see if you can figure it out.
I'll see in the next video we're going to cover a little topic called aggregation but we'll save that
for the next video.
See you soon.