1 00:00:00,540 --> 00:00:01,620 Welcome back. 2 00:00:01,620 --> 00:00:06,500 In the last video we saw a few different ways that we can create an umpire race. 3 00:00:06,570 --> 00:00:09,840 So we got a sample array which could really just be a simple array. 4 00:00:09,870 --> 00:00:15,660 But we're using NDP dot array passing and a list of numbers as another one if we wanted to create an 5 00:00:15,660 --> 00:00:22,000 empty array of just ones we can pass it a shape and if we keep going if we want an array of zeros we 6 00:00:22,000 --> 00:00:24,160 can use empty dot zeros. 7 00:00:24,200 --> 00:00:30,100 We wanted an array that's between a range of different numbers say starts at zero stops at ten steps 8 00:00:30,110 --> 00:00:36,020 at two we can use a range and if we wanted an array of random numbers we've got a few options. 9 00:00:36,070 --> 00:00:43,270 We have Rand int for returning integers between a certain range or we have random at random for returning 10 00:00:43,300 --> 00:00:50,140 numbers between 0 1 of a certain shape and how do we know what these functions do well we compress shift 11 00:00:50,140 --> 00:00:50,740 and tab. 12 00:00:50,740 --> 00:00:52,660 And that's going to return the doc string. 13 00:00:52,660 --> 00:01:00,220 So here we can see N.P. dot random dot random return random floats in the half open interval 0 to 1 14 00:01:00,670 --> 00:01:06,400 and it takes a parameter called size which in our case we've done five and three so five rows three 15 00:01:06,400 --> 00:01:10,380 columns we can see that they're wonderful. 16 00:01:10,420 --> 00:01:17,550 Now he also said in the previous video that none pi generating random numbers they aren't actually random 17 00:01:17,620 --> 00:01:19,500 but you might be running this cell. 18 00:01:19,510 --> 00:01:24,830 I've run this one about 50 odd times and each time new random numbers have come up. 19 00:01:24,880 --> 00:01:26,770 So what's the deal what gives Daniel why. 20 00:01:26,770 --> 00:01:28,720 I think these numbers are random. 21 00:01:28,720 --> 00:01:30,060 Well you'd be right. 22 00:01:30,070 --> 00:01:37,030 They look random to us but what they really are is pseudo random numbers and we can see this by using 23 00:01:37,060 --> 00:01:40,420 num pi random dot seed. 24 00:01:40,420 --> 00:01:45,100 Now throughout your machine learning endeavors you might see this little function at the start of a 25 00:01:45,100 --> 00:01:51,340 notebook or somewhere along lines wherever num plays random package is being used. 26 00:01:51,640 --> 00:01:53,860 Now what does this do now rather than talk about it. 27 00:01:53,860 --> 00:01:56,610 We're going to see what it does in a practical sense. 28 00:01:56,800 --> 00:02:02,280 So let's just comment this out for the time being and we'll just create another one. 29 00:02:02,330 --> 00:02:08,060 You go random array for just so we can make sure it's not the same as this one as before and paid at 30 00:02:08,060 --> 00:02:19,100 random the rand let's go Rand int we want numbers up to 10 of size 5 three wonderful and then we'll 31 00:02:19,100 --> 00:02:23,070 have a look at what this looks like random away for every guy. 32 00:02:23,200 --> 00:02:24,190 Okay numbers. 33 00:02:24,190 --> 00:02:29,120 These are between 0 and 10 0 5 beautiful of size. 34 00:02:29,150 --> 00:02:30,160 Well this is really shape. 35 00:02:30,160 --> 00:02:31,840 That's a bit confusing with implies 36 00:02:34,730 --> 00:02:42,010 is that the size parameter of this creating array function is actually the shape attribute. 37 00:02:42,020 --> 00:02:43,150 That's right. 38 00:02:43,280 --> 00:02:47,810 We can figure these things out with moment to do that but every time if we ran this we're gonna get 39 00:02:48,910 --> 00:02:56,020 what seems to be a new random array and for what we're looking at we can consider this random numbers 40 00:02:56,020 --> 00:02:57,000 every time. 41 00:02:57,190 --> 00:03:04,370 But what if we wanted to share our notebook with someone else and we wanted them to run our cells across 42 00:03:04,370 --> 00:03:09,960 the notebook go through from top to bottom and get exactly the same results as what we did. 43 00:03:10,000 --> 00:03:12,640 So we can reproduce our experiments. 44 00:03:12,790 --> 00:03:20,320 That's when num PIs random seed comes in it allows us to still generate random numbers but random numbers 45 00:03:20,320 --> 00:03:22,180 that are reproducible. 46 00:03:22,180 --> 00:03:23,550 So let's have a look. 47 00:03:23,710 --> 00:03:31,090 If we set random seed at the top of this cell to be zero so we can go shift tab takes a parameter seed 48 00:03:31,120 --> 00:03:33,070 equals something. 49 00:03:33,070 --> 00:03:36,180 So we can actually set this to any number we want. 50 00:03:36,220 --> 00:03:37,360 We'll have to look at any second. 51 00:03:37,360 --> 00:03:39,660 So in this case we'll set it to zero. 52 00:03:39,880 --> 00:03:49,210 We'll hit shift and enter what's happened five out on the numbers of they've stopped changing on us 53 00:03:50,560 --> 00:03:51,480 now what if we comment. 54 00:03:51,480 --> 00:03:54,270 Nissan they've changed. 55 00:03:54,990 --> 00:04:01,540 Okay so what the random seed function does is it essentially says hey um hi. 56 00:04:01,680 --> 00:04:07,140 I want you to create random numbers but keep them aligned with the seed. 57 00:04:07,260 --> 00:04:09,690 So random seed is zero. 58 00:04:09,690 --> 00:04:15,150 We're always gonna see this combination 5 0 3 5 0 3 5 0 3. 59 00:04:15,240 --> 00:04:16,210 I'm running this cell. 60 00:04:16,230 --> 00:04:18,340 We can see the numbers going up here now. 61 00:04:18,690 --> 00:04:24,970 This works no matter what you'll see it is so 6 3 7 6 3 7. 62 00:04:24,990 --> 00:04:32,440 We can't even set it to now and I know 9 0 3 1 0 3 1 huh. 63 00:04:32,790 --> 00:04:36,180 Now let's try again with another random function that was reined in. 64 00:04:36,690 --> 00:04:38,180 Maybe we go here. 65 00:04:38,460 --> 00:04:45,300 Let's go random array 5 just to make sure that it's different NPC not random dot random and shift tab. 66 00:04:45,300 --> 00:04:47,730 What does this take size equals something. 67 00:04:47,790 --> 00:04:49,610 So we want 5 and 3 again. 68 00:04:49,680 --> 00:04:50,700 We had a view. 69 00:04:50,770 --> 00:04:52,160 What's going on here. 70 00:04:52,200 --> 00:04:53,100 Random array. 71 00:04:53,100 --> 00:04:53,760 5. 72 00:04:54,750 --> 00:04:55,050 Okay. 73 00:04:55,070 --> 00:04:57,650 Every time we run this new numbers. 74 00:04:58,320 --> 00:04:59,370 Okay. 75 00:04:59,670 --> 00:05:02,580 Now let's put a random seed in here. 76 00:05:02,700 --> 00:05:03,750 What should we do. 77 00:05:03,750 --> 00:05:05,400 What number are you thinking of. 78 00:05:05,400 --> 00:05:06,900 I'm thinking of seven. 79 00:05:06,930 --> 00:05:10,410 There we got seven. 80 00:05:10,740 --> 00:05:17,720 The numbers still seem seemingly random to me but what the random seed does is remember it says an umpire. 81 00:05:17,730 --> 00:05:23,010 Hey generate some random numbers but if you see the random scene it set to 7. 82 00:05:23,040 --> 00:05:27,830 Make sure they're saying every time the random seed is set to 7. 83 00:05:27,870 --> 00:05:42,550 So now if we run this exact same code in the next cell random array 5 equals a random random 5 3. 84 00:05:42,640 --> 00:05:44,110 Now we want to see it again. 85 00:05:44,120 --> 00:05:47,810 N.P. array 5 different here. 86 00:05:50,950 --> 00:05:57,130 If we kept going with this we would eventually line up with the random seed but we don't have time to 87 00:05:57,130 --> 00:05:57,520 do that. 88 00:05:58,760 --> 00:06:00,470 So what's the takeaway here. 89 00:06:00,500 --> 00:06:09,150 Well the numbers that you see num pi generate seemingly random but they're not actually random. 90 00:06:09,200 --> 00:06:11,290 They're pseudo random numbers. 91 00:06:11,390 --> 00:06:18,170 So whenever we run this function without num pi seed being run what it's actually doing is setting the 92 00:06:18,170 --> 00:06:21,920 seed to be something random every single time you run this. 93 00:06:22,040 --> 00:06:27,540 But if we set our seed manually we're going to get the same random numbers back. 94 00:06:27,740 --> 00:06:35,120 Now the important takeaway is that these numbers are seemingly random but the main purpose of using 95 00:06:35,120 --> 00:06:41,530 random seed is if we wanted someone else to be able to use our notebook and generate random numbers. 96 00:06:41,630 --> 00:06:48,830 But the same random numbers as US and thus reproduce our experiment exactly we would set a random seed. 97 00:06:48,830 --> 00:06:51,980 So if you see any random seed that's what it's doing. 98 00:06:51,980 --> 00:06:58,730 It's making sure the random numbers in the cell that it's been run are the same every single time. 99 00:06:59,400 --> 00:07:02,540 OK now we've seen that we've seen how to create some arrays. 100 00:07:02,540 --> 00:07:05,250 We've seen how to generate arrays with random numbers. 101 00:07:05,660 --> 00:07:09,660 Let's look at how we can view different arrays and matrices. 102 00:07:09,740 --> 00:07:10,970 So take a little break. 103 00:07:10,970 --> 00:07:16,130 Try to generate some more random arrays practice around with no high random seed and I'll see you in 104 00:07:16,130 --> 00:07:16,850 the next video.