Welcome back.
So I believe leave out a little bit of play around with the dot product maybe created your own matrices.
Try it out.
If not that's okay but remember the best way to learn is to always run the code yourself first and then
again maybe if you are even doing that sometimes it's hard to understand like different concepts when
you just seen numbers on a page.
That's always good to try and back things up with a practical example.
So let's have a look at one where the dot product might come into play.
So this is my Google Sheet I'm tracking my nut by the sales for my future not on a business because
my favorite food in the world is almond butter.
And now this business we create 100 percent almond butter 100 percent peanut butter and 100 percent
cashew butter.
And so this is just a simple tracker to track how many jars I've sold on each day.
Friday was a massive day because we sold 15 jars of butter.
Now we've got the prices here of each one.
So I'm about as 10 dollars peanut butter as eight dollars in cash but our cash is a little bit more
expensive so cashew butter is 12 dollars per job.
And now what my goal here is to figure out this total column because that's what I want to know is what
days am I making the most money.
Monday must have been a slow day.
But if we click on this sell here and we have a look at this we can see that this formula is relatively
the same.
Well similar not exactly the same because there's different letters and numbers to our DOT PRODUCT formula.
Back on our slide here.
So a times J plus B times L plus eight times n and that equals 44.
Well if we come back we've got B 2 which is two times B 9 which is the price of almond butter plus C
two in the number of jars of peanut butter times the price of peanut butter and then we've done the
same for cashew butter.
And now we get the total.
So this is an example of where the dot product can come into play is where we want to reduce the numbers
we have here and find out the pattern between them.
So I've got numbers of jars being sold here and the prices and the total price is the patent between
these two.
And I want to emphasize the fact that this can be replicated in pure non pi and panders not just in
an Excel spreadsheet.
So let's put this to the test.
What we're going to do is create a little title here dot product example not by sales and we're going
to recreate this example this whole set here from scratch using nothing but an umpire raise and pander.
So let's do that and.
We'll set a random seed so the random numbers we create are similar to the ones here.
Hopefully that's the idea of random seed.
Now we have sales amounts we go at MP random Rand int we want it up to 20 is a good amount of sales
if I'm selling more than 20 jars I need to step up my supply chain sales amounts.
So this will be we'll put a little comment here.
Number of jars sold there we go 12 15 0 3 3 7 and now we want to create a data frame create weekly sales
data frame.
So this is to put it into pandas so it looks a bit more presentable than just an umpire Ray.
So let's do that.
Weekly sales equals PD data frame.
We want to add our ray sales amounts which we've just created up here.
And then for the indexes will come back our indexes are going to be days of the week so let's do that
index man choose and run out the days of the week.
Wed deliberate aviation so and fry.
Wonderful and then our columns we're going to figure this out we've got a peanut butter cashew butter.
Wonderful columns equals
Allan butter peanut butter
it might seem a bit tedious to type this out we could always export this is a CSB an important panders
but it's always good practice to build your own things from scratch that way you really start to understand
what's happening let's have a look at weekly sales OK.
Wonderful.
So the numbers are a bit different here from what's going on there.
But the process is going to be the same.
So now we've just recreated this section without the total column in a panda's data frame.
Wonderful.
So now we want the prices.
So we want to create the prices array.
We'll keep this the same.
So what are the numbers 10 8 12.
So we can do that with a simple umpire Ray MP or Ray we want 10 8 12.
Wonderful.
Let's have a look so there's a simple num pie array.
Now we want to put that into a data frame as well create a prices data frame bottom prices equals payday
dot data frame prices.
Here index equals so the index is just this column here.
So we want price.
Wonderful price.
And then we want columns is the same as above.
I might just copy this usually we want to write it out but to save a little bit at time of topping this
out we've got the same columns because if we go here same columns wonderful.
Put that in there we've got an extra bracket there we go.
Now let's have a look at our butter prices data from ERA.
Mm hmm.
Wrong number of items past one placement implies three.
We come back.
Shape of past values is three one indices imply 1 3.
Now that's our problem here.
So this is a weird thing in num pi where we go prices not shape it equals three something.
But what panders is expecting is three columns and one row.
But this is three rows one column.
We want to reshape this to be one three there we go.
Wonderful.
So what we've done is we've recreated this little section in Paris.
Beautiful.
So now how do we do this.
We need to do a dot product of sorts on this and this okay.
Then add it to this and this and this and this and add it up and get that.
All right.
So let's try.
So let's just do what we have here.
We've got wins our total sales sales amounts
and prizes.
Let's make total sales equals prices which is we'll have a look at prices again.
Prices.
Sales amounts.
What happens here not aligned.
We want to have a look at our sales amounts actually from this is saying that the shapes are aligned
so we can see that the sales amounts shape is 5 3 and the prices shape is 3 0.
Okay.
That makes sense.
We've we've seen this before we've seen the shapes of dot products not fitting together the shapes on
a line.
We need to transpose shapes aren't aligned.
Let's transpose go.
Total sales.
Which one do we have to transpose.
Maybe if we try to transpose sales amounts total sales equals prices.
Sales amounts T.
There we.
That worked.
Total sales.
Wonderful.
Okay.
Now I've got something that looks kind of like this again.
It's with different numbers.
But now I've got some total sales.
Okay.
So how would we get this as a column on the very right hand side.
Let's have a think.
Let's try something.
Let's just.
If in doubt run the code create daily sales maybe I create the same thing is here but within a panda's
data frame so we can kind of just add the two data frames together.
So let's put up prices which is this yeah.
What else do we want.
We want weekly sales Yeah.
So we want these two.
We want to combine these two through one shape.
No we get weekly sales not shape as well.
OK.
Oh there we go.
So now this is starting to look familiar maybe if we flip weekly sales which is our data frame flip
that transpose that and then dot product of those two because then if we flip these two right there'll
be three on the inside and the threes will line up daily sales equals.
We should be out to do a dot product dot weekly sales dot t so that's a transpose their well that might
have worked because let me prove it to you.
Weekly sales team that's shite.
Excellent.
Here we go.
We might be cooking with gas here.
Oh beautiful.
So this should be the totals.
Now how do we get this onto the right hand side of our data frame.
We want to put this on there here because that's what we're recreating right.
We're putting this total on there.
Okay we can do this how do we create a new column in pandas.
We go weekly sales.
This is our data frame here.
Well weekly sales total maybe I'll put a little dollar sign there.
So we know what's going on here.
Equals daily sales daily sales is this little pandas data frame here I go type daily sales data frame
and we want to add that data frame as a new column on the back end of our data frame here.
So let's see what happens when we do this weekly sales off.
That didn't work.
What's the error here key error.
Total
Total maybe the column title doesn't work.
Wrong number of items past five.
Placement implies one because we're getting into another shape era.
So this is a row.
But we want noted in column form so maybe we have to transpose this.
I cannot stay in shape and then we want the shape of our weekly sales data frame Okay so we want our
daily sales to have the same number of rows as our weekly sales.
And then we should be able to append it.
Okay put a note in here doesn't work not the right shape.
But what we can do is come down we'll make a new cell.
Here we go weekly sales total.
That's a terrible ways to spell it.
Title Daniel weekly sales total equals daily sales dot t for transpose and now the A's hopefully beautiful.
There we go.
So now we've just replicated with a few steps in between of shifting shapes and whatnot.
We've replicated this column here figuring out how much I made from each day Monday was a terrible day
couldn't pay the rent without money.
Well in this state of home it's actually a bit better.
Wednesday was my biggest day and this one we've now seen where manipulating the shapes of arrays and
performing a dot product can work in practice.
So this this video was a lot to take in so I'd go back through and just have a little practice around
maybe create your own store maybe you want to sell your own favorite food product or technology or something
like that make our prices array here make a total column and try to replicate it using num pie panders
and see if you can end up with something like this.
That'll be a good practice exercise.
Okay I forget.
Try to run the code yourself if it doesn't work.
Keep trying.
Search it up and I'll see you in the next video.