Complete the code to create a tensor in PyTorch.
import torch x = torch.[1]([1, 2, 3])
In PyTorch, torch.tensor creates a tensor from a list or array.
Complete the code to move a tensor to GPU if available.
device = torch.device('cuda' if torch.cuda.is_available() else 'cpu') x = x.[1](device)
The to method moves tensors to the specified device, like GPU or CPU.
Fix the error in the code to perform a forward pass in a PyTorch model.
output = model.[1](input_tensor)In PyTorch, the forward method defines the model's computation. Calling model(input) runs forward internally, but explicitly calling forward is correct here.
Fill both blanks to create a dictionary comprehension that maps words to their lengths if length is greater than 3.
{word: [1] for word in words if len(word) [2] 3}The dictionary comprehension maps each word to its length using len(word). The condition filters words with length greater than 3 using >.
Fill all three blanks to create a dictionary comprehension that maps uppercase words to their values if the value is positive.
result = [1]: [2] for k, v in data.items() if v [3] 0}
The comprehension maps uppercase keys k.upper() to their values v only if the value is greater than zero >.