We can't find the internet
Attempting to reconnect
Something went wrong!
Attempting to reconnect
Indexing and Selection
PyTorchSelect tensor elements with slices, index arrays and masks. Distinguish views from copies and understand how indexing affects shape and shared storage.
9 exercises
Explore freely. Sign in to keep your progress.
Your learning sequence
- 1 Not solved yet. Update selected rows, including repeated indices Practice · Medium
- 2 Not solved yet. Pick columns for each row Practice · Medium
- 3 Not solved yet. When two writes land on one slot Practice · Medium
- 4 Not solved yet. Zero the padding, keep the tensor Practice · Easy
- 5 Not solved yet. Mask the padding before the softmax Practice · Easy
- 6 Not solved yet. The value at the argmax Practice · Medium
- 7 Not solved yet. Rows 2 through 5, cheaply Practice · Easy
- 8 Not solved yet. Everything above the threshold Practice · Easy
- 9 Not solved yet. Labels to one-hot Practice · Medium
Check yourself
4 questions · not saved while you're signed outUse these questions to check your understanding and compare explanations. Your score does not affect track completion.
For this two-dimensional tensor, what do the two uses of -1 select?
Choose one answer to reveal the explanations. Answers are kept only while this page is open.
import torch
x = torch.arange(6).reshape(2, 3)
print(x[-1].tolist())
print(x.sum(dim=-1).tolist())