From the course: PyTorch Essential Training: Deep Learning
Unlock the full course today
Join today to access over 23,200 courses taught by industry experts.
Solution: Split tensors to form new tensors
From the course: PyTorch Essential Training: Deep Learning
Solution: Split tensors to form new tensors
(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…