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: Create tensors

Solution: Create tensors

(bright music) - [Instructor] All right, so for this challenge, we needed to create four functions that return four tensors, the first two using the already provided Python list and NumPy array, and the next two by using PyTorch functions. So, here is how to solve this challenge. Since Torch is not supported by CoderPad environment, I have created a mock tensor class that has all required functions to solve this challenge. So we have our first function, which takes input list as parameter. To convert a Python list to a tensor, we'll use a built-in function from the Torch Library called torch.tensor. This function creates a tensor with elements in the same data type as the Python list. In our case, integers. Next, for a second function, which takes an input array and needs to return a two-dimensional tensor, we'll again use the torch.tensor function and pass in an input array as a parameter. To create a tensor of a shape three by four, with all its elements being one, we'll use…

Contents