Skip to content
ml-recall

#cumulative-sum

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

hardAI-checkedPyTorch

a @ t returns the cumulative sum tensor([1, 3, 6, 10]) (Tensor Puzzle 7). What does t @ a return?

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

a = torch.tensor([1, 2, 3, 4])
t = 1 * (arange(4)[:, None] <= arange(4))   # t[r, c] = 1 if r <= c
print(a @ t)
print(t @ a)

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