1 00:00:00,360 --> 00:00:01,410 Welcome back. 2 00:00:01,410 --> 00:00:06,500 So I believe leave out a little bit of play around with the dot product maybe created your own matrices. 3 00:00:06,570 --> 00:00:07,800 Try it out. 4 00:00:08,100 --> 00:00:14,520 If not that's okay but remember the best way to learn is to always run the code yourself first and then 5 00:00:14,520 --> 00:00:19,710 again maybe if you are even doing that sometimes it's hard to understand like different concepts when 6 00:00:19,710 --> 00:00:21,540 you just seen numbers on a page. 7 00:00:21,540 --> 00:00:24,910 That's always good to try and back things up with a practical example. 8 00:00:24,960 --> 00:00:28,410 So let's have a look at one where the dot product might come into play. 9 00:00:28,530 --> 00:00:35,280 So this is my Google Sheet I'm tracking my nut by the sales for my future not on a business because 10 00:00:35,280 --> 00:00:37,910 my favorite food in the world is almond butter. 11 00:00:38,110 --> 00:00:42,840 And now this business we create 100 percent almond butter 100 percent peanut butter and 100 percent 12 00:00:42,870 --> 00:00:43,880 cashew butter. 13 00:00:43,920 --> 00:00:50,400 And so this is just a simple tracker to track how many jars I've sold on each day. 14 00:00:50,400 --> 00:00:54,230 Friday was a massive day because we sold 15 jars of butter. 15 00:00:54,390 --> 00:00:56,850 Now we've got the prices here of each one. 16 00:00:56,850 --> 00:01:01,230 So I'm about as 10 dollars peanut butter as eight dollars in cash but our cash is a little bit more 17 00:01:01,230 --> 00:01:04,910 expensive so cashew butter is 12 dollars per job. 18 00:01:05,000 --> 00:01:10,500 And now what my goal here is to figure out this total column because that's what I want to know is what 19 00:01:10,500 --> 00:01:12,390 days am I making the most money. 20 00:01:12,420 --> 00:01:14,190 Monday must have been a slow day. 21 00:01:14,400 --> 00:01:21,180 But if we click on this sell here and we have a look at this we can see that this formula is relatively 22 00:01:21,180 --> 00:01:22,250 the same. 23 00:01:22,260 --> 00:01:28,770 Well similar not exactly the same because there's different letters and numbers to our DOT PRODUCT formula. 24 00:01:28,860 --> 00:01:30,360 Back on our slide here. 25 00:01:30,840 --> 00:01:36,150 So a times J plus B times L plus eight times n and that equals 44. 26 00:01:36,680 --> 00:01:45,860 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 27 00:01:45,860 --> 00:01:51,870 two in the number of jars of peanut butter times the price of peanut butter and then we've done the 28 00:01:51,870 --> 00:01:53,390 same for cashew butter. 29 00:01:53,670 --> 00:01:55,460 And now we get the total. 30 00:01:55,500 --> 00:02:01,200 So this is an example of where the dot product can come into play is where we want to reduce the numbers 31 00:02:01,200 --> 00:02:04,130 we have here and find out the pattern between them. 32 00:02:04,170 --> 00:02:10,290 So I've got numbers of jars being sold here and the prices and the total price is the patent between 33 00:02:10,290 --> 00:02:10,950 these two. 34 00:02:11,540 --> 00:02:17,980 And I want to emphasize the fact that this can be replicated in pure non pi and panders not just in 35 00:02:17,980 --> 00:02:18,990 an Excel spreadsheet. 36 00:02:18,990 --> 00:02:20,430 So let's put this to the test. 37 00:02:20,430 --> 00:02:30,230 What we're going to do is create a little title here dot product example not by sales and we're going 38 00:02:30,230 --> 00:02:37,850 to recreate this example this whole set here from scratch using nothing but an umpire raise and pander. 39 00:02:37,870 --> 00:02:39,130 So let's do that and. 40 00:02:39,310 --> 00:02:44,130 We'll set a random seed so the random numbers we create are similar to the ones here. 41 00:02:44,260 --> 00:02:47,340 Hopefully that's the idea of random seed. 42 00:02:47,350 --> 00:02:56,020 Now we have sales amounts we go at MP random Rand int we want it up to 20 is a good amount of sales 43 00:02:56,020 --> 00:03:01,630 if I'm selling more than 20 jars I need to step up my supply chain sales amounts. 44 00:03:01,630 --> 00:03:05,320 So this will be we'll put a little comment here. 45 00:03:05,500 --> 00:03:21,550 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 46 00:03:22,360 --> 00:03:24,340 data frame. 47 00:03:24,340 --> 00:03:28,720 So this is to put it into pandas so it looks a bit more presentable than just an umpire Ray. 48 00:03:28,750 --> 00:03:29,590 So let's do that. 49 00:03:29,590 --> 00:03:34,750 Weekly sales equals PD data frame. 50 00:03:35,020 --> 00:03:39,520 We want to add our ray sales amounts which we've just created up here. 51 00:03:39,520 --> 00:03:46,920 And then for the indexes will come back our indexes are going to be days of the week so let's do that 52 00:03:47,130 --> 00:03:52,050 index man choose and run out the days of the week. 53 00:03:52,090 --> 00:03:56,800 Wed deliberate aviation so and fry. 54 00:03:56,860 --> 00:04:04,770 Wonderful and then our columns we're going to figure this out we've got a peanut butter cashew butter. 55 00:04:04,880 --> 00:04:07,520 Wonderful columns equals 56 00:04:10,300 --> 00:04:12,960 Allan butter peanut butter 57 00:04:15,940 --> 00:04:21,000 it might seem a bit tedious to type this out we could always export this is a CSB an important panders 58 00:04:21,300 --> 00:04:26,550 but it's always good practice to build your own things from scratch that way you really start to understand 59 00:04:26,550 --> 00:04:30,250 what's happening let's have a look at weekly sales OK. 60 00:04:30,350 --> 00:04:30,950 Wonderful. 61 00:04:31,010 --> 00:04:34,660 So the numbers are a bit different here from what's going on there. 62 00:04:34,670 --> 00:04:36,470 But the process is going to be the same. 63 00:04:36,470 --> 00:04:43,480 So now we've just recreated this section without the total column in a panda's data frame. 64 00:04:43,490 --> 00:04:44,690 Wonderful. 65 00:04:44,690 --> 00:04:46,100 So now we want the prices. 66 00:04:46,190 --> 00:04:48,900 So we want to create the prices array. 67 00:04:49,100 --> 00:04:50,230 We'll keep this the same. 68 00:04:50,230 --> 00:04:53,080 So what are the numbers 10 8 12. 69 00:04:53,300 --> 00:05:02,270 So we can do that with a simple umpire Ray MP or Ray we want 10 8 12. 70 00:05:02,540 --> 00:05:03,170 Wonderful. 71 00:05:03,710 --> 00:05:07,310 Let's have a look so there's a simple num pie array. 72 00:05:07,380 --> 00:05:19,260 Now we want to put that into a data frame as well create a prices data frame bottom prices equals payday 73 00:05:19,450 --> 00:05:23,740 dot data frame prices. 74 00:05:24,100 --> 00:05:30,690 Here index equals so the index is just this column here. 75 00:05:30,690 --> 00:05:32,450 So we want price. 76 00:05:32,790 --> 00:05:34,770 Wonderful price. 77 00:05:34,800 --> 00:05:38,520 And then we want columns is the same as above. 78 00:05:38,520 --> 00:05:43,050 I might just copy this usually we want to write it out but to save a little bit at time of topping this 79 00:05:43,050 --> 00:05:50,810 out we've got the same columns because if we go here same columns wonderful. 80 00:05:50,980 --> 00:05:55,190 Put that in there we've got an extra bracket there we go. 81 00:05:55,210 --> 00:06:00,490 Now let's have a look at our butter prices data from ERA. 82 00:06:00,810 --> 00:06:03,430 Mm hmm. 83 00:06:03,430 --> 00:06:08,180 Wrong number of items past one placement implies three. 84 00:06:08,370 --> 00:06:09,370 We come back. 85 00:06:09,520 --> 00:06:14,050 Shape of past values is three one indices imply 1 3. 86 00:06:14,090 --> 00:06:15,940 Now that's our problem here. 87 00:06:15,940 --> 00:06:23,190 So this is a weird thing in num pi where we go prices not shape it equals three something. 88 00:06:23,200 --> 00:06:29,230 But what panders is expecting is three columns and one row. 89 00:06:29,230 --> 00:06:31,570 But this is three rows one column. 90 00:06:31,600 --> 00:06:37,490 We want to reshape this to be one three there we go. 91 00:06:37,760 --> 00:06:38,330 Wonderful. 92 00:06:38,330 --> 00:06:44,150 So what we've done is we've recreated this little section in Paris. 93 00:06:44,330 --> 00:06:45,230 Beautiful. 94 00:06:45,230 --> 00:06:48,080 So now how do we do this. 95 00:06:48,080 --> 00:06:54,970 We need to do a dot product of sorts on this and this okay. 96 00:06:54,990 --> 00:07:00,380 Then add it to this and this and this and this and add it up and get that. 97 00:07:00,500 --> 00:07:00,970 All right. 98 00:07:01,670 --> 00:07:02,850 So let's try. 99 00:07:02,870 --> 00:07:05,550 So let's just do what we have here. 100 00:07:05,600 --> 00:07:09,380 We've got wins our total sales sales amounts 101 00:07:13,010 --> 00:07:14,180 and prizes. 102 00:07:15,110 --> 00:07:22,430 Let's make total sales equals prices which is we'll have a look at prices again. 103 00:07:22,430 --> 00:07:25,940 Prices. 104 00:07:26,820 --> 00:07:28,700 Sales amounts. 105 00:07:28,740 --> 00:07:33,540 What happens here not aligned. 106 00:07:33,580 --> 00:07:41,900 We want to have a look at our sales amounts actually from this is saying that the shapes are aligned 107 00:07:41,940 --> 00:07:49,320 so we can see that the sales amounts shape is 5 3 and the prices shape is 3 0. 108 00:07:49,320 --> 00:07:49,630 Okay. 109 00:07:49,650 --> 00:07:50,400 That makes sense. 110 00:07:50,400 --> 00:07:56,130 We've we've seen this before we've seen the shapes of dot products not fitting together the shapes on 111 00:07:56,130 --> 00:07:56,520 a line. 112 00:07:56,520 --> 00:08:02,770 We need to transpose shapes aren't aligned. 113 00:08:03,010 --> 00:08:06,430 Let's transpose go. 114 00:08:06,460 --> 00:08:08,140 Total sales. 115 00:08:08,140 --> 00:08:11,050 Which one do we have to transpose. 116 00:08:11,170 --> 00:08:18,320 Maybe if we try to transpose sales amounts total sales equals prices. 117 00:08:19,130 --> 00:08:22,850 Sales amounts T. 118 00:08:22,960 --> 00:08:23,440 There we. 119 00:08:23,450 --> 00:08:24,050 That worked. 120 00:08:24,050 --> 00:08:26,130 Total sales. 121 00:08:26,210 --> 00:08:27,240 Wonderful. 122 00:08:27,340 --> 00:08:27,980 Okay. 123 00:08:28,090 --> 00:08:30,690 Now I've got something that looks kind of like this again. 124 00:08:30,710 --> 00:08:32,230 It's with different numbers. 125 00:08:32,390 --> 00:08:34,280 But now I've got some total sales. 126 00:08:34,280 --> 00:08:35,540 Okay. 127 00:08:35,630 --> 00:08:40,210 So how would we get this as a column on the very right hand side. 128 00:08:40,250 --> 00:08:42,640 Let's have a think. 129 00:08:42,950 --> 00:08:43,740 Let's try something. 130 00:08:43,760 --> 00:08:44,090 Let's just. 131 00:08:44,090 --> 00:08:52,550 If in doubt run the code create daily sales maybe I create the same thing is here but within a panda's 132 00:08:52,610 --> 00:08:56,300 data frame so we can kind of just add the two data frames together. 133 00:08:56,540 --> 00:09:04,260 So let's put up prices which is this yeah. 134 00:09:04,350 --> 00:09:05,040 What else do we want. 135 00:09:05,040 --> 00:09:08,590 We want weekly sales Yeah. 136 00:09:08,660 --> 00:09:09,610 So we want these two. 137 00:09:09,610 --> 00:09:13,390 We want to combine these two through one shape. 138 00:09:13,400 --> 00:09:16,340 No we get weekly sales not shape as well. 139 00:09:18,060 --> 00:09:18,480 OK. 140 00:09:18,840 --> 00:09:19,710 Oh there we go. 141 00:09:20,010 --> 00:09:25,860 So now this is starting to look familiar maybe if we flip weekly sales which is our data frame flip 142 00:09:25,860 --> 00:09:31,560 that transpose that and then dot product of those two because then if we flip these two right there'll 143 00:09:31,560 --> 00:09:37,350 be three on the inside and the threes will line up daily sales equals. 144 00:09:37,560 --> 00:09:49,070 We should be out to do a dot product dot weekly sales dot t so that's a transpose their well that might 145 00:09:49,070 --> 00:09:51,250 have worked because let me prove it to you. 146 00:09:51,410 --> 00:09:54,020 Weekly sales team that's shite. 147 00:09:54,830 --> 00:09:56,060 Excellent. 148 00:09:56,060 --> 00:09:57,050 Here we go. 149 00:09:57,050 --> 00:09:58,480 We might be cooking with gas here. 150 00:09:58,540 --> 00:10:00,260 Oh beautiful. 151 00:10:00,380 --> 00:10:01,760 So this should be the totals. 152 00:10:01,770 --> 00:10:05,510 Now how do we get this onto the right hand side of our data frame. 153 00:10:05,510 --> 00:10:08,470 We want to put this on there here because that's what we're recreating right. 154 00:10:08,480 --> 00:10:09,920 We're putting this total on there. 155 00:10:10,830 --> 00:10:16,320 Okay we can do this how do we create a new column in pandas. 156 00:10:16,330 --> 00:10:17,740 We go weekly sales. 157 00:10:17,740 --> 00:10:19,520 This is our data frame here. 158 00:10:19,530 --> 00:10:25,780 Well weekly sales total maybe I'll put a little dollar sign there. 159 00:10:26,170 --> 00:10:27,630 So we know what's going on here. 160 00:10:27,640 --> 00:10:38,100 Equals daily sales daily sales is this little pandas data frame here I go type daily sales data frame 161 00:10:38,520 --> 00:10:44,710 and we want to add that data frame as a new column on the back end of our data frame here. 162 00:10:44,710 --> 00:10:50,330 So let's see what happens when we do this weekly sales off. 163 00:10:50,420 --> 00:10:52,070 That didn't work. 164 00:10:52,070 --> 00:10:54,760 What's the error here key error. 165 00:10:54,770 --> 00:10:55,280 Total 166 00:10:57,910 --> 00:11:02,930 Total maybe the column title doesn't work. 167 00:11:02,930 --> 00:11:05,180 Wrong number of items past five. 168 00:11:05,180 --> 00:11:11,090 Placement implies one because we're getting into another shape era. 169 00:11:11,180 --> 00:11:12,840 So this is a row. 170 00:11:13,160 --> 00:11:17,870 But we want noted in column form so maybe we have to transpose this. 171 00:11:18,520 --> 00:11:28,300 I cannot stay in shape and then we want the shape of our weekly sales data frame Okay so we want our 172 00:11:28,330 --> 00:11:32,620 daily sales to have the same number of rows as our weekly sales. 173 00:11:32,620 --> 00:11:34,850 And then we should be able to append it. 174 00:11:34,840 --> 00:11:42,420 Okay put a note in here doesn't work not the right shape. 175 00:11:43,090 --> 00:11:46,710 But what we can do is come down we'll make a new cell. 176 00:11:46,820 --> 00:11:51,410 Here we go weekly sales total. 177 00:11:51,610 --> 00:11:53,070 That's a terrible ways to spell it. 178 00:11:53,080 --> 00:12:06,300 Title Daniel weekly sales total equals daily sales dot t for transpose and now the A's hopefully beautiful. 179 00:12:06,330 --> 00:12:07,320 There we go. 180 00:12:07,320 --> 00:12:12,650 So now we've just replicated with a few steps in between of shifting shapes and whatnot. 181 00:12:12,720 --> 00:12:19,290 We've replicated this column here figuring out how much I made from each day Monday was a terrible day 182 00:12:19,320 --> 00:12:21,500 couldn't pay the rent without money. 183 00:12:21,540 --> 00:12:24,130 Well in this state of home it's actually a bit better. 184 00:12:24,150 --> 00:12:30,480 Wednesday was my biggest day and this one we've now seen where manipulating the shapes of arrays and 185 00:12:30,480 --> 00:12:33,770 performing a dot product can work in practice. 186 00:12:33,810 --> 00:12:39,240 So this this video was a lot to take in so I'd go back through and just have a little practice around 187 00:12:39,480 --> 00:12:44,970 maybe create your own store maybe you want to sell your own favorite food product or technology or something 188 00:12:44,970 --> 00:12:52,470 like that make our prices array here make a total column and try to replicate it using num pie panders 189 00:12:52,830 --> 00:12:54,750 and see if you can end up with something like this. 190 00:12:54,750 --> 00:12:56,430 That'll be a good practice exercise. 191 00:12:56,850 --> 00:12:58,270 Okay I forget. 192 00:12:58,390 --> 00:13:00,600 Try to run the code yourself if it doesn't work. 193 00:13:00,600 --> 00:13:01,330 Keep trying. 194 00:13:01,350 --> 00:13:03,630 Search it up and I'll see you in the next video.