mindspore.ops.tril
- mindspore.ops.tril(input, diagonal=0)[源代码]
将指定对角线上方的元素设置为0。
- 参数:
input (Tensor) - 输入tensor,其秩至少为2。
diagonal (int,可选) - 二维tensor的指定对角线。默认
0
,表示主对角线。
- 返回:
Tensor
- 支持平台:
Ascend
GPU
CPU
样例:
>>> import mindspore >>> input = mindspore.tensor([[ 1, 2, 3, 4], ... [ 5, 6, 7, 8], ... [10, 11, 12, 13], ... [14, 15, 16, 17]]) >>> mindspore.ops.tril(input) Tensor(shape=[4, 4], dtype=Int64, value= [[ 1, 0, 0, 0], [ 5, 6, 0, 0], [10, 11, 12, 0], [14, 15, 16, 17]]) >>> mindspore.ops.tril(input, 1) Tensor(shape=[4, 4], dtype=Int64, value= [[ 1, 2, 0, 0], [ 5, 6, 7, 0], [10, 11, 12, 13], [14, 15, 16, 17]]) >>> mindspore.ops.tril(input, -1) Tensor(shape=[4, 4], dtype=Int64, value= [[ 0, 0, 0, 0], [ 5, 0, 0, 0], [10, 11, 0, 0], [14, 15, 16, 0]]) >>> input = mindspore.tensor([[[ 1, 2, 3], ... [ 5, 6, 7], ... [10, 11, 12]], ... [[ 1, 2, 3], ... [ 5, 6, 7], ... [10, 11, 12]]]) >>> mindspore.ops.tril(input) Tensor(shape=[2, 3, 3], dtype=Int64, value= [[[ 1, 0, 0], [ 5, 6, 0], [10, 11, 12]], [[ 1, 0, 0], [ 5, 6, 0], [10, 11, 12]]])