‫Welcome back.
‫Hopefully you've had a little bit of a play around with creating your own numpy arrays, 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
‫numpy arrays.
‫And so in the previous section of video we went through creating some of our own arrays, a to 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.
‫So sample array how we did it the first time.
‫Import array and we passed it.
‫A list of numbers.
‫Wonderful.
‫We'll go here.
‫And just so it prints out, we'll have sampler right here.
‫So this is going to give us a one dimensional numpy array with the elements one, two and three in it.
‫So if we check this arrays data type.
‫Here we go.
‫Beautiful.
‫Okay.
‫Now, for example, what if we wanted to create an umpire, Ray, 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 cold ones and you go empty ones, actually.
‫What does empty ones?
‫What do you think that would 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 whilst we're inside the brackets.
‫Oh.
‫What have we got here?
‫Signature NPCs, ones shape.
‫Docstring return a new array of given shape and type filled with ones beautiful.
‫So what shift and tab does?
‫Remember, we'll exit out of here.
‫We'll come back into this if we type in any kind of function.
‫So import something brackets, we push shift and tab while we're inside here.
‫What that's going to tell Jupiter do is open up the function's docstring.
‫So this gives us information.
‫So this information here comes straight from the numpy documentation.
‫This is going to tell us what this function does.
‫Return a new array of given shape and type filled with ones.
‫Let's see here parameters, shape, int or sequence of events e.g. two three.
‫Let's use that example.
‫Two, three.
‫Shifting into.
‫Okay.
‫What does this look like?
‫Want are.
‫An array filled with ones.
‫That's exactly what it said.
‫Shift and 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 it shape.
‫Okay, let's have a look here.
‫One dot D type.
‫That's daytime float.
‫So if we use ones, pretty sure 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 docstring.
‫Let's keep going.
‫If we checked type of one, we can see that it's our beautiful and favorite data type is end de array.
‫Wonderful.
‫Now let's have a look.
‫What if we wanted another array but not with ones we wanted one with zeros.
‫MP Let's see.
‫MP zero So does it have this?
‫Docstring return a new array of given shape and type filled with zeros.
‫Okay, let's do the same again.
‫Input.
‫Zeros.
‫Wonderful.
‫Okay.
‫Now, you might be thinking, Danielle, why would you want ones?
‫Why would you want zeros?
‫Well, in that case, you could imagine zeros is kind of like a placeholder 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 and p 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.
‫Okay.
‫Let's have a look.
‫Hmm.
‫Start number.
‫Stop number.
‫Step number.
‫Let's try it.
‫If in doubt, always try zero ten two.
‫Now this is going to be start, stop step.
‫What do we think that this will return?
‫Let's have a look.
‫Ranger Ray.
‫Ah, so it's going to start at zero zero.
‫It's going to stop at ten, but it's going to step up by two 0 to 4, six, eight.
‫Wonderful.
‫Let's keep pushing forward.
‫Let's go.
‫Random array.
‫What if we didn't know what numbers?
‫We just want num pi to just fill an array full of random information for us and beat out random.
‫Let's do rend int, shift and tab.
‫Let's practice.
‫Docstring ran low high size return random integers from low to high exclusive okay return integers from
‫the discrete uniform distribution of the specified d type parameters low int or array of ints high int
‫or array like of int optional size oc.
‫So let's go zero ten size three by five.
‫What do you think this will return?
‫Let's have a look.
‫Random array.
‫Size is not defined.
‫Ah.
‫What have we done wrong here?
‫We haven't set size equal.
‫Wonderful.
‫So what this has done, we'll see what the actual docstring return random integers from low.
‫This is our low zero, low inclusive to high exclusive ten of size three by five.
‫So now if we go random array dot size, we have 15 and we want random array dot shape.
‫Three five.
‫Wonderful.
‫And we can see that in our REA.
‫The low is zero and the high is ten.
‫Wonderful.
‫Let's see one more way of creating random arrays.
‫Random, random, num pi has a fair few different ways of creating random arrays.
‫You don't need to know them all.
‫There we go.
‫So random.
‫Random.
‫What does this do?
‫Shift tab.
‫Return random floats in the half open interval zero one.
‫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 to wonderful random array two.
‫Let's check the shape.
‫Shape.
‫There we go.
‫Shape is five and three.
‫Wonderful.
‫So that means it's always rows, then columns.
‫So five rows, three columns.
‫One, two, three, four, five, three columns.
‫And if we check this, it's going to be between the interval zero and one.
‫Wonderful.
‫Go to random array and let's say one more.
‫So we want random array three.
‫Now this is where numpy can get a bit confusing.
‫Is that these dot rand or random and random five three do very similar things.
‫Hmm.
‫Random.
‫We've got a shift tab.
‫We can see what the docstring says here.
‫Return values in a given shape.
‫So that's what I've done past D0 and D1.
‫So Dimension zero is five and Dimension one is three.
‫So remember always goes.
‫Dimension zero.
‫Dimension one.
‫If we go back to the anatomy of our numpy array, axis zero is the same as dimension zero, which is
‫the row here, and access one is the same as dimension one, which is the columns here.
‫Wonderful.
‫Now, the thing you should know about the random numbers in NumPy is they aren't actually random.
‫They're set with something called a random seed and by a random seed.
‫Hmm.
‫What could this mean there?
‫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 NumPy 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 int.
‫Have a look at the doc strings by pressing shift tab.
‫And then in the next video we'll have a look at MP random seed and see how we can generate some non
‫random random numbers.