1 00:00:00,630 --> 00:00:01,980 Welcome back. 2 00:00:01,980 --> 00:00:08,070 We've had a little bit of a play around with creating your own umpire race but if not that's okay because 3 00:00:08,070 --> 00:00:15,250 in this section what we're going to do now is have a look at how we can create an umpire race. 4 00:00:15,780 --> 00:00:24,120 And so in the previous section of video we went through creating some of our own arrays a two a three 5 00:00:24,450 --> 00:00:28,290 a one and we learnt about different attributes that these arrays had. 6 00:00:28,440 --> 00:00:35,440 But it was very tedious typing out all of these different numbers so let's have a look at some easier 7 00:00:35,440 --> 00:00:36,000 ways. 8 00:00:36,010 --> 00:00:40,570 First to begin with we'll just see it again just in case you sample array. 9 00:00:40,570 --> 00:00:46,420 How we did it the first time MP dot array and we passed it a list of numbers. 10 00:00:46,420 --> 00:00:48,200 Wonderful. 11 00:00:48,360 --> 00:00:50,940 We'll go here and just sell Prince out. 12 00:00:51,040 --> 00:00:52,940 We'll have a sample array here. 13 00:00:52,950 --> 00:01:00,130 So this is going to give us a one dimensional none pie array with the elements 1 2 and 3 in it so if 14 00:01:00,130 --> 00:01:04,910 we check this arrays data type There we go. 15 00:01:04,910 --> 00:01:06,140 Beautiful. 16 00:01:06,170 --> 00:01:06,900 Okay. 17 00:01:06,940 --> 00:01:09,860 Now for example what if we wanted to create an umpire right. 18 00:01:09,860 --> 00:01:11,390 That was already filled for us. 19 00:01:11,390 --> 00:01:14,570 What if we didn't want to pass any anything here. 20 00:01:14,630 --> 00:01:16,430 Let's have a look at how you could do that. 21 00:01:16,430 --> 00:01:22,760 Let's make one called once and you go empty ones actually. 22 00:01:22,940 --> 00:01:25,970 What does empty dot ones what do you think that will be. 23 00:01:25,970 --> 00:01:31,660 Well I've got a little trick I can show you to get a little preview of this let's hit shift and TAB 24 00:01:31,730 --> 00:01:37,720 walls were inside the brackets Oh what have we got here. 25 00:01:37,780 --> 00:01:45,830 Signature NDP dot ones shape dock string return a new array of given shape and type filled with ones 26 00:01:46,300 --> 00:01:47,630 beautiful. 27 00:01:47,630 --> 00:01:53,450 So what shift in Tab does remember will exit out of here come back into this if we type in any kind 28 00:01:53,450 --> 00:01:54,550 of functions are empty. 29 00:01:54,550 --> 00:01:56,400 Dot something brackets. 30 00:01:56,410 --> 00:02:02,630 If we push shift and tab while we're inside here what that's gonna tell duper to do is open up the functions 31 00:02:02,780 --> 00:02:10,010 dock string so this gives us information so this information here comes straight from the NUM pi documentation. 32 00:02:10,140 --> 00:02:16,370 This is going to tell us what this function does return a new array of given shape and type filled with 33 00:02:16,370 --> 00:02:17,670 ones. 34 00:02:17,670 --> 00:02:23,000 Well let's see here parameters shape into or sequence of ints e.g. 2 3. 35 00:02:23,030 --> 00:02:28,030 Let's use that example two three shift and enter. 36 00:02:28,400 --> 00:02:28,940 Okay. 37 00:02:29,000 --> 00:02:36,790 What does this look like ones are an array filled with ones that's exactly what it said shift in tab 38 00:02:37,030 --> 00:02:42,880 return a new array of given shape and type filled with ones and we haven't put in type here but we have 39 00:02:42,880 --> 00:02:44,060 given its shape. 40 00:02:44,640 --> 00:02:45,080 Okay. 41 00:02:45,100 --> 00:02:46,100 Let's have a look here. 42 00:02:46,120 --> 00:02:50,140 One stock D time that's D type float. 43 00:02:50,140 --> 00:02:54,970 So if we use one's pretty short float is the default data type. 44 00:02:54,980 --> 00:03:00,010 Now you could probably find that that's a little challenge for you is to find out what the default data 45 00:03:00,010 --> 00:03:02,530 type is by reading through the dock string. 46 00:03:03,220 --> 00:03:04,580 Let's keep going. 47 00:03:04,600 --> 00:03:07,870 We checked type of 1. 48 00:03:07,870 --> 00:03:13,120 We can see that it's our beautiful and favorite data type is Andy array. 49 00:03:13,150 --> 00:03:14,800 Wonderful. 50 00:03:14,800 --> 00:03:15,410 Now let's have a look. 51 00:03:15,550 --> 00:03:19,160 If we wanted another array but not with ones we wanted one with zeros. 52 00:03:19,210 --> 00:03:21,950 MP let's see empty zeros. 53 00:03:21,960 --> 00:03:29,030 Does it have this dock string return a new array of given shape and type filled with zeros. 54 00:03:29,040 --> 00:03:31,950 Okay let's do the same again. 55 00:03:32,100 --> 00:03:36,630 You don't zeros zeros wonderful. 56 00:03:36,680 --> 00:03:37,560 Okay. 57 00:03:37,760 --> 00:03:41,750 Now you might be thinking why would you want ones why would you want zeros. 58 00:03:41,750 --> 00:03:48,110 Well in that case you could imagine zeros is kind of like a place holder array maybe in machine learning 59 00:03:48,110 --> 00:03:53,180 you want to fill an array with some initial data or that data you don't know yet. 60 00:03:53,180 --> 00:03:57,980 So you create the zeros just to work out the shapes of data you're working with. 61 00:03:57,980 --> 00:04:03,800 So before you even implement any data you could make sure that your shapes lined up by using arrays 62 00:04:03,800 --> 00:04:05,030 filled with zeros. 63 00:04:05,270 --> 00:04:06,140 But let's keep going. 64 00:04:06,140 --> 00:04:09,380 Let's see how we could make a few more different kinds of arrays. 65 00:04:09,470 --> 00:04:09,860 Let's go. 66 00:04:09,860 --> 00:04:13,230 Range array equals empty. 67 00:04:13,270 --> 00:04:15,160 Got a range. 68 00:04:15,200 --> 00:04:16,460 Let's see shift and tab. 69 00:04:16,460 --> 00:04:18,440 That's what we're practicing at the moment. 70 00:04:18,440 --> 00:04:22,250 Return evenly spaced values within a given interval. 71 00:04:22,250 --> 00:04:23,770 Start Stop. 72 00:04:23,870 --> 00:04:25,740 Step OK. 73 00:04:25,780 --> 00:04:28,750 Let's have a look Mm hmm. 74 00:04:28,960 --> 00:04:29,470 Start. 75 00:04:29,530 --> 00:04:30,810 No stop. 76 00:04:30,820 --> 00:04:32,020 No. 77 00:04:32,020 --> 00:04:32,560 Step. 78 00:04:32,560 --> 00:04:33,240 No. 79 00:04:33,250 --> 00:04:34,000 Let's try it. 80 00:04:34,000 --> 00:04:36,130 If in doubt always try. 81 00:04:36,130 --> 00:04:38,770 0 10 2. 82 00:04:38,800 --> 00:04:41,050 Now this is gonna be start stop. 83 00:04:41,050 --> 00:04:45,490 Step what do we think that this will return let's have a look. 84 00:04:45,550 --> 00:04:48,410 Ranger Ray huh. 85 00:04:48,690 --> 00:04:51,430 So it's gonna start at 0 0. 86 00:04:51,540 --> 00:04:57,210 It's gonna stop at 10 but it's gonna step up by 2 0 2 4 6 8. 87 00:04:57,210 --> 00:04:57,960 Wonderful. 88 00:04:58,470 --> 00:05:00,000 Let's keep pushing forward. 89 00:05:00,000 --> 00:05:02,640 Well let's go random array. 90 00:05:02,640 --> 00:05:04,710 What if we didn't know what numbers we just want now. 91 00:05:04,720 --> 00:05:10,330 Paul and I just fill an array full of random information for us and beat out random. 92 00:05:10,670 --> 00:05:16,160 Let's do Rand int shift in town let's practice doctoring. 93 00:05:16,290 --> 00:05:17,340 Rand low. 94 00:05:17,480 --> 00:05:18,070 Hi. 95 00:05:18,110 --> 00:05:26,580 Sighs return random and taggers from low to high exclusive K return and taggers from the discreet uniform 96 00:05:26,580 --> 00:05:35,610 distribution of the specified daytime parameters low end or array of ints high int or array like of 97 00:05:35,610 --> 00:05:38,410 ints optional size. 98 00:05:38,640 --> 00:05:43,340 Okay so let's go 0 10. 99 00:05:43,470 --> 00:05:47,120 Size 3 by 5. 100 00:05:47,200 --> 00:05:48,580 What do you think this will return. 101 00:05:48,910 --> 00:05:54,070 Let's have a look random array size is not defined. 102 00:05:54,180 --> 00:05:55,230 What have we done wrong here. 103 00:05:55,230 --> 00:05:58,040 We haven't set size equal. 104 00:05:58,280 --> 00:05:59,240 Wonderful. 105 00:05:59,270 --> 00:06:00,720 So what this is done. 106 00:06:00,920 --> 00:06:05,090 They will see what the actual dock string return random I take is from low. 107 00:06:05,090 --> 00:06:07,530 This is our low 0 low. 108 00:06:07,850 --> 00:06:14,270 Inclusive to high exclusive 10 of size 3 by 5. 109 00:06:14,300 --> 00:06:21,860 So now if we go random array dot size we have 15. 110 00:06:21,980 --> 00:06:27,150 We want random array dot shape 3 5. 111 00:06:27,160 --> 00:06:27,760 Wonderful. 112 00:06:27,760 --> 00:06:33,990 And we can see that in our array the low is 0 and the high is 10. 113 00:06:34,000 --> 00:06:34,690 Wonderful. 114 00:06:34,810 --> 00:06:42,910 Let's see one more way of creating random arrays random dot random num Pi has a fair few different ways 115 00:06:42,910 --> 00:06:47,210 of creating random arrays don't need to know them all. 116 00:06:47,880 --> 00:06:54,670 Now we go so random dot random what does this do shift tab return random floats in the half open interval 117 00:06:55,000 --> 00:06:56,760 0 1. 118 00:06:56,800 --> 00:07:00,600 So this is going to return and it takes a parameter size. 119 00:07:01,240 --> 00:07:07,440 Let's save this to random array to and then we want to show it. 120 00:07:07,440 --> 00:07:12,380 Random array 2 wonderful random array 2. 121 00:07:12,390 --> 00:07:13,290 Let's check the shape. 122 00:07:14,820 --> 00:07:15,210 Shape. 123 00:07:15,210 --> 00:07:15,930 There we go. 124 00:07:15,930 --> 00:07:26,070 Shape is 5 and 3 wonderful SO THAT MEANS IT'S ALWAYS rows then columns so 5 rows 3 columns 1 2 3 4 5 125 00:07:26,570 --> 00:07:27,810 3 columns. 126 00:07:27,810 --> 00:07:32,230 And if we check this it's going to be between the interval 0 and 1. 127 00:07:32,250 --> 00:07:33,400 Wonderful. 128 00:07:33,540 --> 00:07:36,430 Got a random array and let's see one more. 129 00:07:36,570 --> 00:07:38,750 So we want random array 3. 130 00:07:38,760 --> 00:07:45,780 Now this is where an umpire can get a bit confusing is that these dot Rand or random and Dot random 131 00:07:46,910 --> 00:07:52,980 5 3 do very similar things. 132 00:07:54,090 --> 00:07:57,960 Random random will go to shift tab. 133 00:07:58,170 --> 00:08:00,450 We can see what the doc string says here. 134 00:08:00,450 --> 00:08:02,270 Return values in a given shape. 135 00:08:02,280 --> 00:08:10,740 So that's what I've done past D 0 and d 1 so dimensions 0 is 5 and dimension 1 is 3. 136 00:08:10,740 --> 00:08:14,650 Remember always goes to mentioned 0 dimension 1. 137 00:08:14,670 --> 00:08:23,190 If we go back to the anatomy of our num pi array axis 0 is the same as dimension 0 which is the row 138 00:08:23,190 --> 00:08:28,320 here and access 1 is the same as dimension one which is the columns here. 139 00:08:28,380 --> 00:08:35,900 Wonderful Now the thing you should know about the random numbers in num pies they aren't actually random. 140 00:08:36,110 --> 00:08:41,890 They're set with something called a random seed pie not random seed. 141 00:08:41,950 --> 00:08:49,200 What could this mean they're pseudo random numbers and pseudo random numbers. 142 00:08:49,240 --> 00:08:51,040 We'll have a look at this in the next video. 143 00:08:51,720 --> 00:08:57,310 But this is an important concept to remember going forward is that when num pi generates random numbers 144 00:08:57,520 --> 00:09:00,030 they're actually pseudo random numbers. 145 00:09:00,130 --> 00:09:08,500 So take a quick break try practice creating some of your own random arrays using the DOT random or Rand 146 00:09:08,550 --> 00:09:09,240 end. 147 00:09:09,280 --> 00:09:16,030 Have a look at the docs strings by pressing shift tab and then the next video will have a look at MP 148 00:09:16,120 --> 00:09:21,670 dot random seed and see how we can generate some non random random numbers.