‫Welcome back.
‫In the last video we had a look at Nam PI's random number generator and how it's random, but we can
‫use Nam PI's random seed method to make it not so random and create pseudo random numbers.
‫Now we're going to have a look at different ways of viewing arrays and matrices.
‫There we go.
‫Shift and enter.
‫Remember, we're making markdown cells so that our notebooks are beautifully formatted.
‫And actually, before we jump into that.
‫How do you think we'd find the unique numbers in these arrays?
‫Maybe this one is a bit better because that's got integers.
‫These are all floats here, and they're way too long.
‫But how would we find the unique numbers in random array for.
‫Let's have a practice of how we might do that.
‫So we'll open up a tab and we'll go.
‫How to find unique elements in an umpire.
‫A beautiful that's pre-filled.
‫It's going to take us to the documentation.
‫NOM pi unique.
‫Find the unique elements of an array.
‫Wonderful.
‫That's what we're after.
‫So if we go down in the documentation, you'll see down the bottom.
‫There's examples.
‫Now, this is what we're after.
‫This is the process you can go through.
‫Say, someone came to us and was like, Hey, you've got your random array for I need the unique numbers
‫from that.
‫So we find the documentation, we'd come to the example section or we just read it to see if it does
‫what we need.
‫Then we'd have a look down here.
‫So they've got an array, a MP, unique, a array.
‫It shows a unique numbers there.
‫Well, let's have a look.
‫Let's practice EMP dot unique and remember if we hit shift and tab.
‫We've got information here.
‫Find the unique elements of an array.
‫Wonderful.
‫That's what we're after.
‫So we're going to pass at random array for.
‫Random array for.
‫Shift and enter.
‫And what this has given us is zero one, two, three, four, five, six, eight, nine.
‫If we come up here and that is because we created random array for using rand int past at ten.
‫So that means it'll use the numbers between zero and nine of size five and three so we can see the uniques.
‫We haven't quite got all the numbers between zero and nine.
‫We're missing two or missing seven.
‫Beautiful.
‫But that's just a quick little tidbit of how you might find a function using numpy.
‫You might come across a documentation.
‫StackOverflow is another resource that you'll often come across, but that's the steps you take.
‫Now let's get into section three.
‫Viewing arrays and matrices.
‫So we've got our RES, A1, A2, we created these earlier A3.
‫Now viewing arrays and matrices takes a bit of practice and creating them, of course, too.
‫But if what you're seeing in this section, how to view them is a little bit confusing to start, don't
‫worry, I still get confused.
‫The important point is to start practicing.
‫So if we want to see element zero in A1, we could use zero indexing.
‫So let's try that.
‫Beautiful.
‫Let's go.
‫The same for A2.
‫Wonderful.
‫Now, this is going to give us this first row here.
‫Why is that?
‫Well, if we go above here a two dot shape.
‫Okay, so it's got two rows, so that makes sense.
‫We're indexing into the first element of the shape.
‫Now let's try a3a3 dot shape.
‫This is two, three, three.
‫Let's get a30.
‫Wonderful.
‫But if we have a look at all of a three, so it's giving us back the first row.
‫So if we see here, two, three, three.
‫And i30 is giving us back this first matrix or first array and remember the anatomy of our arrays and
‫matrices.
‫Although this is still an umpire, Ray, it can be referred to as a matrix.
‫And this is where some of the terminology gets a bit confusing.
‫Usually a one dimensional array is referred to as a vector, but anything more than one dimensional
‫is referred to as a matrix, but is also of type array.
‫So that's the important thing to take away is that a array is still this, but anything with more than
‫one dimension is a matrix.
‫Let's have a look at some more indexing.
‫So we've got a two maybe if we wanted index one.
‫So we'll have a look at our rate again, index one.
‫What will this give us, do you think?
‫Shift and enter are.
‫So it's given us position one.
‫So let's try again.
‫Let's do a bit more of a complicated one.
‫We can use slicing with arrays too, which is beautiful.
‫Just like python less.
‫Maybe we want the first two values of a three, so we want the first two values of each row, column
‫and array.
‫So let's try that first two values of each shape.
‫What do you think this will give?
‫So let's have a look.
‫So we got the first two and the second two, which is one, two, four, five.
‫So it's this section.
‫And then we got the final two, which is ten, 11, 13, 14 are beautiful.
‫Now, remember doing this kind of indexing, depending on how many dimensions your arrays have, will
‫take some practicing here.
‫So best to just experiment, create some arrays and start playing around.
‫What if we did something like this?
‫You'd get an error because there's too many indices.
‫The reason why we can only do three is because of a threes shape.
‫There we go.
‫Two, three, three.
‫Let's try one more.
‫We'll create a four equals random rand.
‫Oh, no.
‫We need an umpire at the front here.
‫Random dot rand int would do ten.
‫And this time we'll make it a four dimensional array.
‫Two, three, four, five.
‫We want to see it shift.
‫An entire size is not defined.
‫Oh, we keep forgetting to push equals here.
‫That's right.
‫You'll make some errors too, when you're learning to code here.
‫Okay, so a four.
‫We've got a fair few numbers here.
‫We can scroll right down.
‫So if we did a four point shape and then a four and Dem.
‫The shape is two, three, four, five.
‫We kind of knew that.
‫So two by three.
‫By four by five.
‫Yep.
‫And the dimensions is four.
‫So this is a four dimensional array, remember?
‫And dimensions can go up to any number you can imagine.
‫So how would we get only the first four numbers of this vector here?
‫Hmm.
‫Let's have a look at this size.
‫So NumPy displays arrays from the outside integer inwards.
‫So let's have a look at this.
‫This might be a bit hard to understand, but with some practice you'll start to see.
‫So we got five here.
‫So the furthest element on the right, the furthest of the shape gets displayed on the innermost section.
‫So five.
‫There's five numbers here.
‫And then for the next section is this section here.
‫So there's one, two, three, four.
‫Yeah.
‫And then three.
‫So there should be three.
‫One, two, three.
‫Yep.
‫So one, two, three, and then two.
‫So there should be two in the largest.
‫So the outermost brackets.
‫So this this is three and this is three here.
‫So there's two there.
‫Remember, visualizing these is very hard to understand when you first begin.
‫So if you're having some trouble, try to create some random arrays with different shapes and then start
‫to count backwards from the outermost number.
‫On the innermost displayed array.
‫But let's say, how would we get the first four numbers of the inner most array?
‫So that's the innermost here, number five.
‫So what we could do is slice these first three dimensions and then slice this one.
‫We only want the first four.
‫So let's try that A4 slice.
‫All of dimension one slice, all of dimension two, all of dimension three, but only up to the first
‫four numbers of dimension four.
‫Shift and enter.
‫Wonderful.
‫So that only gives us the first four numbers of the innermost dimension.
‫And if we got rid of that to three, that to two.
‫Here we go.
‫We can start to see how we can really slice and dice our arrays and and matrices to give us back any
‫kind of numbers that we might want to see.
‫All right.
‫Now, we've seen a few different ways to create arrays.
‫We've seen a few different ways to index them and view them.
‫And I'm using the term array and matrix independently.
‫You can use them independently yourself.
‫What we're going to do next is figure out how to manipulate and compare different arrays, which is
‫the crux of what machine learning does to find patterns in numbers.
‫So have some practice, take a little break, try out a bit of slicing, create your own array and see
‫different ways of viewing it.
‫And I'll see you in the next video.