The simplest and best solution is to use torch.sum() . To sum all elements of a tensor: torch.sum(outputs) # gives back a scalar.
確定! 回上一頁