Welcome back.
In the last video we had a look at none pie's random number generator and how it's random but we can
use no highs 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.
Here we go shift in into when 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.
Beautiful that's pretty filled it's going gonna take us to the documentation known pi dot 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 examples 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 MPD unique and remember 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 it random array for random array for shift and enter.
And what this has given us is 0 1 3 4 5 6 8 9.
If we come up here and that is because we created random array for using Rand int past at 10 so that
means it will use the numbers between 0 and 9 of size 5 and 3.
So we can see the uniques we haven't quite got all the numbers between 0 and 9 we're missing 2 0 missing
7 beautiful but that's just a quick little tidbit of how you might find a function using num pi you
might come across the documentation stack overflow is another resource that you will often come across
but that's the steps you take.
Now let's get into a section three viewing arrays and matrices.
So we've got our arrays a one a two we created these earlier a three Now viewing arrays and matrices
takes a bit of practice and created them of course to but if what you're seeing in this section had
a view them is a little bit confusing a start.
Don't worry I still get confused.
The important point is to start practicing.
So if we wanted to see element zero in a one we could use zero indexing.
So let's try that beautiful.
Let's go the same for A2 wonderful.
Now this is gonna give us this first row here.
Why is that.
Well if we go above here a two dots 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 a three a 3-D art shape.
This is two three three.
Let's get a 3 0.
Wonderful.
But if we have a look at all of A3 so it's giving us back the first row.
So if we see here two three three in a three 0 is giving us back this first matrix or first array I
remember the anatomy of our arrays and matrices although this is still an umpire Ray it can be referred
to as a matrix.
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 the 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 have a two.
Maybe if we wanted index one.
So we'll have a look at our Reagan index 1 what will this give us do you think shift and enter.
So it's given us position 1.
So let's try again.
Let's do a bit more of a complicated one we can use slicing with arrays 2 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.
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've got the first two.
And the second two which is one two four five sets this section and then we've got the final two which
is 10 11 13 14.
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 3D shape.
There we go two three three.
Let's try one more we'll create a four equals random dot Rand on it.
We need an umpire at the front here random dot Rand end would do 10 and this time or make it a four
dimensional array two three four five.
We want to see it shift in into size is not defined OK.
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 forward shape and then a 4 a.m. the shape is 2 3 4 5 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.
Let's have a look at this size so none pi displays arrays from the outside integer inwards.
So let's have a look at this.
It's might be a bit hard to understand but with some practice you'll start to see.
So we've 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.
Yeah.
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 inner most displayed array but let's say how would
we get the first four numbers of that in a 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 a four slice all of dimension 1 slice all of dimension to all of dimension 3 but only
up to the first four numbers of dimension 4 shift into wonderful.
So that only gives us the first four numbers of the innermost dimension.
And if we got rid of packed of three that two there 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 taking 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.