In this section, we shall start with tensor basics.
Then we'll move on to casting and tensor flow.
We'll look at initialization, indexing, broadcasting, algebraic operations, matrix operations,
commonly used functions in machine learning.
We'll look at the different types of tensors, like the ranked tensors, sparse tensors and even the
string tensors in the context of deep learning.
Tensors can be defined as multi-dimensional arrays.
An array itself is an ordered arrangement of numbers.
It's important we take note of these keywords as the data we shall be dealing with.
Like, for example, this image right here can be represented using this numbers which have been arranged
clearly in an ordered manner and can be represented in multiple dimensions.
In this specific case, we have this array which is represented in one two dimensions.
So this is A to Z or two dimensional array or what we generally call a matrix.
Now we'll explore different types of arrays based on their dimensionality.
So here, for example, we have what we'll call a zero dimensional array, which is simply because this
array or this tensor contains a single element.
So let's say we have 21.
This is a zero dimensional array.
Let's say we have one, this is zero dimensional, so on and so forth.
So essentially once we have a single element, then it's A0D array.
And then now for our next example, we have this 1D tensor right here, which in fact is a combination
of several zero D tensors.
So if you look at this, you see that this is A0D tensor, this is another zero D tensor, this is another
zero D tensor.
So this vector is made of three of these kinds of elements.
Now, we could have other examples like this.
Let's say we have five, um, eight and then three.
Oh, let's, let's, let's change the length.
So let's say we have one of length five, for example, we could have ten two, 11, four and seven.
So this is a 1D tensor we have right here.
So, so far we've looked at the zero D tensor, we've looked at the 1D tensor and now we could dive
into the 2D tensor, which essentially is made of a combination of several 1D tensors.
You could see that right here.
This is a 1D tensor here, this is another 1D tensor, this is another 1D tensor.
And finally here we have a 1D tensor.
So when you bring together this 1D tensors, you form this 2D tensor for a three dimensional tensor.
You might have guessed this right?
You would simply combine several two dimensional tensors.
So right here we have this 2D tensor with this other 2D, with this other 2D and this other 2D forming
a 3D tensor.
We could visualize this differently here.
So we take this, this, this and this.
Now you see we have one, two and the third dimension.
Now that we understand this, we are going to take a look at the concept of tensor shapes, starting
with this.
Given that it's zero dimensional, then there is no shape with this one here.
It's one dimensional and it's made of three elements.
And so we could say this is of shape three.
So we have three and that's it.
Now for this other one, it's made of one, two, three and four 1D tensors, and each and every one
of these is made of three elements.
So this here, for example, is made of three elements.
This made of three, this three, this three.
And given that there are four of this made of three elements, its shape is four by three.
So that's it.
That's how we obtain the shape for this.
Now for the 3D tensor we have here is made of one, two, three, four 2D tensors.
So this year we have four two uh, 2d tensors and each and every one of these is made of two 1D tensors
where each and every one is made of three elements.
So what we'll see here is this is two by three this year because we have one, two is two by three,
this is two by three and this here is two by three.
And now given that we have four of this different two by three 2D tensors, then we would say the shape
of this 3D tensor is four by two by three.
So similar to this, we have four by three.
This is four by two by three.
Now notice that the number of elements we have here tells us or gives us information about the number
of dimensions our tensor is.
So here because we have a 1D tensor or one dimensional tensor, we have just one here because it's 2D
or two dimensional, we have two and here because it's 3D, we have three.
Also in matrix notation, we would say that this year or this matrix right here is made of one two.
Three and four rows.
So number of rows we have here is four.
And then here we have one, two, three columns.
Number of columns is three.
In the case of this 3D tensor we have right here, we have one two rows and one, two, three columns
for each and every one of this 2D tensor we have right here.