Skip to content
ml-recall

#bucketize

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

What is out?

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

def ones(i):
    return arange(i) * 0 + 1

v = torch.tensor([4, 0, 3, 9])
boundaries = torch.tensor([1, 3, 5])
out = (1 * (v[:, None] >= boundaries)) @ ones(3)

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