Complete the code to create a tensor with values [1, 2, 3].
import torch x = torch.[1]([1, 2, 3]) print(x)
The torch.tensor function creates a tensor from a list of numbers.
Complete the code to add two tensors x and y.
import torch x = torch.tensor([1, 2]) y = torch.tensor([3, 4]) z = x [1] y print(z)
The plus sign + adds two tensors element-wise.
Fix the error in the code to multiply tensor x by 2.
import torch x = torch.tensor([1, 2, 3]) y = x [1] 2 print(y)
The * operator multiplies each element of the tensor by 2.
Fill both blanks to create a tensor of zeros with shape (2, 3) and print its shape.
import torch zeros_tensor = torch.[1]((2, 3)) print(zeros_tensor.[2])
torch.zeros creates a tensor filled with zeros. The shape attribute shows its dimensions.
Fill all three blanks to create a tensor from a list, convert it to float type, and print its data type.
import torch x = torch.tensor([1, 2, 3]).[1]([2]) print(x.[3])
The to method converts the tensor to a new type. torch.float32 is the float type. The dtype attribute shows the tensor's data type.
