Question 1: Short answer
mediumAI-checkedInformation TheoryThis is the d2l entropy function. What does the last line return?
import torch
def nansum(x):
return x[~torch.isnan(x)].sum()
def entropy(p):
return nansum(-p * torch.log2(p))
entropy(torch.tensor([0.5, 0.25, 0.25, 0.0]))