torch.trace¶ torch.trace(input) → Tensor¶ 傳回輸入 2 維矩陣對角線元素的總和。 範例 >>> x = torch.arange(1., 10.).view(3, 3) >>> x tensor([[ 1., 2., 3.], [ 4., 5., 6.], [ 7., 8., 9.]]) >>> torch.trace(x) tensor(15.)