(upbeat music)
- [Lecturer] For this challenge,
we need to implement four functions
using PyTorch building functions.
Here is how we solve this challenge.
Our task involves splitting two tensors, x and y,
using PyTorch chunk and split functions.
We use the chunk function when we want to divide the tensor
into specified number of smaller tensors.
It attempts to divide them as evenly as possible.
For the first implementation, I have called chunk function
with parameter four and a dimension value equal to zero.
This means we are dividing tensor x
into four smaller tensors along the first dimension or rows.
You can think of it as splitting the matrix
into four smaller matrices,
each with roughly the same number of rows.
For the second task, I've used chunk four,
which splits one dimensional tensor y
into four smaller 1d tensors.
Since y has 16 elements, each chunk will have four elements.
For third task, we use split
since we need more control over the sizes
of the resulting tensors.
In this case, we specified the exact size of each chunk.
We split x into two parts, the first with five rows
and second with three rows along first dimension.
Lastly, we split y into three chunks
with the specified lengths.
The first chunk has four elements
and the next two have six elements each.
Finally, if you go ahead and click on Test My Code,
you can see that that is the right answer,
and we can scroll through
and see all of our modified tensors.