API
torch.triu(input, diagonal=0, out=None) → Tensor
返回上三角矩阵
参数 | 描述 |
---|---|
input (Tensor) | the input tensor. |
diagonal (int, optional) | the diagonal to consider |
out (Tensor, optional) | the output tensor. |
>>> a = torch.randn(3, 3)
>>> a
tensor([[ 0.2309, 0.5207, 2.0049],
[ 0.2072, -1.0680, 0.6602],
[ 0.3480, -0.5211, -0.4573]])
>>> torch.triu(a)
tensor([[ 0.2309, 0.5207, 2.0049],
[ 0.0000, -1.0680, 0.6602],
[ 0.0000, 0.0000, -0.4573]])
参考:
https://pytorch.org/docs/master/generated/torch.triu.html?highlight=torch%20triu#torch.triu