【发布时间】:2020-11-21 03:30:40
【问题描述】:
在the official example of PyTorch中,给出如下损失函数。
def nll(input, target):
return -input[range(target.shape[0]), target].mean()
loss_func = nll
如何理解上述函数中“input[range(target.shape[0]), target]”的语法? “输入”有一个 torch.Size([64, 10]),“目标”有一个 torch.Size([64])。为什么在这里使用“range”函数?
【问题讨论】: