Welcome back.
We've had a little bit of a play around with creating your own umpire race but if not that's okay because
in this section what we're going to do now is have a look at how we can create an umpire race.
And so in the previous section of video we went through creating some of our own arrays a two a three
a one and we learnt about different attributes that these arrays had.
But it was very tedious typing out all of these different numbers so let's have a look at some easier
ways.
First to begin with we'll just see it again just in case you sample array.
How we did it the first time MP dot array and we passed it a list of numbers.
Wonderful.
We'll go here and just sell Prince out.
We'll have a sample array here.
So this is going to give us a one dimensional none pie array with the elements 1 2 and 3 in it so if
we check this arrays data type There we go.
Beautiful.
Okay.
Now for example what if we wanted to create an umpire right.
That was already filled for us.
What if we didn't want to pass any anything here.
Let's have a look at how you could do that.
Let's make one called once and you go empty ones actually.
What does empty dot ones what do you think that will be.
Well I've got a little trick I can show you to get a little preview of this let's hit shift and TAB
walls were inside the brackets Oh what have we got here.
Signature NDP dot ones shape dock string return a new array of given shape and type filled with ones
beautiful.
So what shift in Tab does remember will exit out of here come back into this if we type in any kind
of functions are empty.
Dot something brackets.
If we push shift and tab while we're inside here what that's gonna tell duper to do is open up the functions
dock string so this gives us information so this information here comes straight from the NUM pi documentation.
This is going to tell us what this function does return a new array of given shape and type filled with
ones.
Well let's see here parameters shape into or sequence of ints e.g. 2 3.
Let's use that example two three shift and enter.
Okay.
What does this look like ones are an array filled with ones that's exactly what it said shift in tab
return a new array of given shape and type filled with ones and we haven't put in type here but we have
given its shape.
Okay.
Let's have a look here.
One stock D time that's D type float.
So if we use one's pretty short float is the default data type.
Now you could probably find that that's a little challenge for you is to find out what the default data
type is by reading through the dock string.
Let's keep going.
We checked type of 1.
We can see that it's our beautiful and favorite data type is Andy array.
Wonderful.
Now let's have a look.
If we wanted another array but not with ones we wanted one with zeros.
MP let's see empty zeros.
Does it have this dock string return a new array of given shape and type filled with zeros.
Okay let's do the same again.
You don't zeros zeros wonderful.
Okay.
Now you might be thinking why would you want ones why would you want zeros.
Well in that case you could imagine zeros is kind of like a place holder array maybe in machine learning
you want to fill an array with some initial data or that data you don't know yet.
So you create the zeros just to work out the shapes of data you're working with.
So before you even implement any data you could make sure that your shapes lined up by using arrays
filled with zeros.
But let's keep going.
Let's see how we could make a few more different kinds of arrays.
Let's go.
Range array equals empty.
Got a range.
Let's see shift and tab.
That's what we're practicing at the moment.
Return evenly spaced values within a given interval.
Start Stop.
Step OK.
Let's have a look Mm hmm.
Start.
No stop.
No.
Step.
No.
Let's try it.
If in doubt always try.
0 10 2.
Now this is gonna be start stop.
Step what do we think that this will return let's have a look.
Ranger Ray huh.
So it's gonna start at 0 0.
It's gonna stop at 10 but it's gonna step up by 2 0 2 4 6 8.
Wonderful.
Let's keep pushing forward.
Well let's go random array.
What if we didn't know what numbers we just want now.
Paul and I just fill an array full of random information for us and beat out random.
Let's do Rand int shift in town let's practice doctoring.
Rand low.
Hi.
Sighs return random and taggers from low to high exclusive K return and taggers from the discreet uniform
distribution of the specified daytime parameters low end or array of ints high int or array like of
ints optional size.
Okay so let's go 0 10.
Size 3 by 5.
What do you think this will return.
Let's have a look random array size is not defined.
What have we done wrong here.
We haven't set size equal.
Wonderful.
So what this is done.
They will see what the actual dock string return random I take is from low.
This is our low 0 low.
Inclusive to high exclusive 10 of size 3 by 5.
So now if we go random array dot size we have 15.
We want random array dot shape 3 5.
Wonderful.
And we can see that in our array the low is 0 and the high is 10.
Wonderful.
Let's see one more way of creating random arrays random dot random num Pi has a fair few different ways
of creating random arrays don't need to know them all.
Now we go so random dot random what does this do shift tab return random floats in the half open interval
0 1.
So this is going to return and it takes a parameter size.
Let's save this to random array to and then we want to show it.
Random array 2 wonderful random array 2.
Let's check the shape.
Shape.
There we go.
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
3 columns.
And if we check this it's going to be between the interval 0 and 1.
Wonderful.
Got a random array and let's see one more.
So we want random array 3.
Now this is where an umpire can get a bit confusing is that these dot Rand or random and Dot random
5 3 do very similar things.
Random random will go to shift tab.
We can see what the doc string says here.
Return values in a given shape.
So that's what I've done past D 0 and d 1 so dimensions 0 is 5 and dimension 1 is 3.
Remember always goes to mentioned 0 dimension 1.
If we go back to the anatomy of our num pi array axis 0 is the same as dimension 0 which is the row
here and access 1 is the same as dimension one which is the columns here.
Wonderful Now the thing you should know about the random numbers in num pies they aren't actually random.
They're set with something called a random seed pie not random seed.
What could this mean they're pseudo random numbers and pseudo random numbers.
We'll have a look at this in the next video.
But this is an important concept to remember going forward is that when num pi generates random numbers
they're actually pseudo random numbers.
So take a quick break try practice creating some of your own random arrays using the DOT random or Rand
end.
Have a look at the docs strings by pressing shift tab and then the next video will have a look at MP
dot random seed and see how we can generate some non random random numbers.