Skip to content
ml-recall

#negative-indices

1 question from PyTorch

Timed test

1 question · 1 min · score and explanations at the end

Take a test
Q 1 / 1Score 0 / 0

Question 1: Short answer

mediumAI-checkedPyTorch

A first attempt at Tensor Puzzle 8 (running difference) needs the previous element of each position. What is prev?

def arange(i):
    return torch.tensor(range(i))

a = torch.tensor([5, 7, 2, 9])
prev = a[arange(4) - 1]

Four integers, e.g. [3, 1, 0, 2]