Complete the code to select the first row of the tensor.
import torch x = torch.tensor([[1, 2], [3, 4], [5, 6]]) first_row = x[1]
The first row of a tensor is accessed by using index 0 inside square brackets.
Complete the code to select the last column of the tensor.
import torch x = torch.tensor([[1, 2, 3], [4, 5, 6]]) last_col = x[1]
To select the last column, use ':' for all rows and '-1' for the last column index.
Fix the error in the code to correctly slice the tensor to get rows 1 and 2.
import torch x = torch.tensor([[10, 20], [30, 40], [50, 60]]) subset = x[1]
Slicing uses start:stop syntax, and stop is exclusive. To get rows 1 and 2, use 1:3.
Fill both blanks to select the middle column and rows 0 and 1.
import torch x = torch.tensor([[1, 2, 3], [4, 5, 6], [7, 8, 9]]) subset = x[1][2]
Use [0:2] to select rows 0 and 1, and [:, 1] to select the middle column.
Fill all three blanks to create a tensor slice with rows 1 to 2 and columns 0 to 1.
import torch x = torch.tensor([[5, 10, 15], [20, 25, 30], [35, 40, 45]]) subset = x[1][2][3]
Use [1:3] to select rows 1 and 2, and [:, 0:2] to select columns 0 and 1.
