Welcome back.
In the last video we saw a few different ways that we can create an umpire race.
So we got a sample array which could really just be a simple array.
But we're using NDP dot array passing and a list of numbers as another one if we wanted to create an
empty array of just ones we can pass it a shape and if we keep going if we want an array of zeros we
can use empty dot zeros.
We wanted an array that's between a range of different numbers say starts at zero stops at ten steps
at two we can use a range and if we wanted an array of random numbers we've got a few options.
We have Rand int for returning integers between a certain range or we have random at random for returning
numbers between 0 1 of a certain shape and how do we know what these functions do well we compress shift
and tab.
And that's going to return the doc string.
So here we can see N.P. dot random dot random return random floats in the half open interval 0 to 1
and it takes a parameter called size which in our case we've done five and three so five rows three
columns we can see that they're wonderful.
Now he also said in the previous video that none pi generating random numbers they aren't actually random
but you might be running this cell.
I've run this one about 50 odd times and each time new random numbers have come up.
So what's the deal what gives Daniel why.
I think these numbers are random.
Well you'd be right.
They look random to us but what they really are is pseudo random numbers and we can see this by using
num pi random dot seed.
Now throughout your machine learning endeavors you might see this little function at the start of a
notebook or somewhere along lines wherever num plays random package is being used.
Now what does this do now rather than talk about it.
We're going to see what it does in a practical sense.
So let's just comment this out for the time being and we'll just create another one.
You go random array for just so we can make sure it's not the same as this one as before and paid at
random the rand let's go Rand int we want numbers up to 10 of size 5 three wonderful and then we'll
have a look at what this looks like random away for every guy.
Okay numbers.
These are between 0 and 10 0 5 beautiful of size.
Well this is really shape.
That's a bit confusing with implies
is that the size parameter of this creating array function is actually the shape attribute.
That's right.
We can figure these things out with moment to do that but every time if we ran this we're gonna get
what seems to be a new random array and for what we're looking at we can consider this random numbers
every time.
But what if we wanted to share our notebook with someone else and we wanted them to run our cells across
the notebook go through from top to bottom and get exactly the same results as what we did.
So we can reproduce our experiments.
That's when num PIs random seed comes in it allows us to still generate random numbers but random numbers
that are reproducible.
So let's have a look.
If we set random seed at the top of this cell to be zero so we can go shift tab takes a parameter seed
equals something.
So we can actually set this to any number we want.
We'll have to look at any second.
So in this case we'll set it to zero.
We'll hit shift and enter what's happened five out on the numbers of they've stopped changing on us
now what if we comment.
Nissan they've changed.
Okay so what the random seed function does is it essentially says hey um hi.
I want you to create random numbers but keep them aligned with the seed.
So random seed is zero.
We're always gonna see this combination 5 0 3 5 0 3 5 0 3.
I'm running this cell.
We can see the numbers going up here now.
This works no matter what you'll see it is so 6 3 7 6 3 7.
We can't even set it to now and I know 9 0 3 1 0 3 1 huh.
Now let's try again with another random function that was reined in.
Maybe we go here.
Let's go random array 5 just to make sure that it's different NPC not random dot random and shift tab.
What does this take size equals something.
So we want 5 and 3 again.
We had a view.
What's going on here.
Random array.
5.
Okay.
Every time we run this new numbers.
Okay.
Now let's put a random seed in here.
What should we do.
What number are you thinking of.
I'm thinking of seven.
There we got seven.
The numbers still seem seemingly random to me but what the random seed does is remember it says an umpire.
Hey generate some random numbers but if you see the random scene it set to 7.
Make sure they're saying every time the random seed is set to 7.
So now if we run this exact same code in the next cell random array 5 equals a random random 5 3.
Now we want to see it again.
N.P. array 5 different here.
If we kept going with this we would eventually line up with the random seed but we don't have time to
do that.
So what's the takeaway here.
Well the numbers that you see num pi generate seemingly random but they're not actually random.
They're pseudo random numbers.
So whenever we run this function without num pi seed being run what it's actually doing is setting the
seed to be something random every single time you run this.
But if we set our seed manually we're going to get the same random numbers back.
Now the important takeaway is that these numbers are seemingly random but the main purpose of using
random seed is if we wanted someone else to be able to use our notebook and generate random numbers.
But the same random numbers as US and thus reproduce our experiment exactly we would set a random seed.
So if you see any random seed that's what it's doing.
It's making sure the random numbers in the cell that it's been run are the same every single time.
OK now we've seen that we've seen how to create some arrays.
We've seen how to generate arrays with random numbers.
Let's look at how we can view different arrays and matrices.
So take a little break.
Try to generate some more random arrays practice around with no high random seed and I'll see you in
the next video.