‫Welcome back.
‫So I believe you had a little bit of play around with the DOT product, maybe created your own matrices,
‫tried 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 see numbers on a page.
‫It'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 butter sales for my future nut butter business because my favorite food in the world
‫is almond butter.
‫And now this business, we create 100% almond butter, 100% peanut butter, and 100% 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 almond butter.
‫Now we've got the prices here of each one.
‫So almond what is $10?
‫Peanut butter is $8 in cashew butter.
‫Cashews are a little bit more expensive.
‫So cashew butter is $12 per jar.
‫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 cell here and we have a look at this, we
‫can see that this formula is relatively the same or 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 C, times N, and that equals 44.
‫Well, if we come back, we've got B two, which is two times B nine, 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've 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 pattern between
‫these two.
‫And I want to emphasize the fact that this can be replicated in pure numpy and pandas, 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, a dot product example, not a sales.
‫And we're going to recreate this example.
‫This whole set here from scratch, using nothing but numpy arrays and pandas.
‫So let's do that.
‫NumPy will set a random seed, so the random numbers we create are similar to the ones here.
‫Hopefully that's the idea of random seed and we have sales amounts, we go and paid a 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.
‫1215 0337.
‫And now we want to create a dataframe, create weekly sales dataframe.
‫So this is to put it into panda so it looks a bit more presentable than just an umpire.
‫Ray So let's do that.
‫Weekly sales equals PD DataFrame.
‫We want to add our ray sales amounts, which you've just created up here.
‫And then for the indexes, we'll come back.
‫Our indexes are going to be days of the week.
‫So let's do that index.
‫Choose and write out the days of the week.
‫Wed Little Abbreviations All Day and Fry.
‫Wonderful.
‫And then our columns, we're going to fix this up.
‫We've got almond butter, peanut butter, cashew butter.
‫Wonderful columns equals.
‫Almond butter.
‫Peanut butter.
‫It might seem a bit tedious to type this out.
‫We could always export this as a CSV and import and pandas, 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.
‫Okay.
‫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 pandas data frame.
‫Wonderful.
‫So now we want the prices.
‫So we want create the prices array.
‫We'll keep this the same.
‫So what are the numbers?
‫Ten, eight, 12.
‫So we can do that with a simple numpy array.
‫MP array.
‫We want ten, eight, 12.
‫One, two, four.
‫Let's have a look.
‫So there's a simple umpire, Ray.
‫Now we want to put that into a data frame as well.
‫Create better prices, data frame.
‫We have bottom prices equals paydays.
‫DataFrame.
‫Prices you want 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 of time of typing this out, we've got the
‫same columns because if we go here, same columns.
‫Wonderful.
‫Put that in there.
‫Oh, we've got an extra bracket.
‫There we go.
‫Now let's have a look at our butter prices.
‫DataFrame.
‫Era.
‫Hmm.
‫Wrong number of items passed.
‫One placement implies three.
‫We come back.
‫Shape of pass values is three.
‫One indices imply one three are.
‫Now, that's our problem here.
‫So this is a weird thing in numpy where we go, price is not shape, it equals three something.
‫But what pandas 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 pandas.
‫Beautiful.
‫So now.
‫How do we do this?
‫We need to do a dot product of sorts on this and this.
‫Okay.
‫And 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 have we have here.
‫We've got where's our total sales?
‫Sales amounts.
‫Yup.
‫And prices.
‫Let's make total sales equals prices, which is we'll have a look at prices again, prices.
‫Dot sales amounts.
‫What happens here?
‫Not aligned.
‫We want to have a look at our sales amounts, actually.
‫Hmm.
‫And this is saying that the shapes aren't aligned.
‫So we can see that the sales amounts shape is five three and the prices shape is three zero.
‫That makes sense.
‫We've seen this before.
‫We've seen the shapes of products not fitting together.
‫The shapes aren't aligned.
‫We need to transpose.
‫Shapes aren't aligned.
‫Let's transpose.
‫If I go total sales, which one do we have to transpose?
‫Maybe if we try to transpose sales amounts.
‫Total sales eagles prices dot sales amounts dot t.
‫Oh, there we go.
‫That worked.
‫Total sales.
‫Wonderful.
‫Now I've got something that looks kind of like this again.
‫It's with different numbers, but now we'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.
‫Hmm.
‫Let's try something.
‫Let's just, if in doubt, run the code, create daily sales.
‫Maybe I create the same thing as here, but within a pandas data frame.
‫So we can kind of just add the two data frames together.
‫So let's battle prices, which is this.
‫Yep.
‫What else do we want?
‫We want weekly sales.
‫Yeah.
‫So we want these to, we want to combine these two.
‫So we want shape.
‫Maybe we get weekly sales dot shape as well.
‫OC.
‫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 able to do a dot product dot weekly sales dot
‫T, so that's a transpose there.
‫Well, that might have worked because let me prove it to you.
‫Weekly sales t shape.
‫Excellent.
‫Here we go.
‫We might be cooking with gas here.
‫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 dataframe here.
‫We want weekly sales total.
‫Maybe we'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.
‫We're going to go type daily sales.
‫DataFrame.
‫And we want to add that DataFrame 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.
‫Oh, that didn't work.
‫What's the error here?
‫K era total.
‫Total.
‫Maybe the title doesn't work.
‫Wrong number of items past five placement implies one.
‫Ah, because we're getting into another shape error.
‫So this is a row.
‫But we want that in column form, so maybe we have to transpose this.
‫Okay, let's do shape.
‫And then we want the shape of our weekly sales data frame.
‫Ah.
‫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.
‫We put a note in here.
‫It doesn't work.
‫Not the right shape.
‫But what we can do is come down and we'll make a new cell.
‫There we go.
‫Weekly sales total.
‫That's a terrible waste spelling title, Daniel.
‫Weekly sales total equals daily sales.
‫44 transpose.
‫And now this, 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 dataframe, it's actually a bit better.
‫Wednesday was my biggest day in 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 a prices array here, make a total column and try to replicate it using numpy and pandas 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.