mindspore.ops.tril

View Source On Gitee
mindspore.ops.tril(input, diagonal=0)[source]

Zero the input tensor above the diagonal specified.

Parameters
  • input (Tensor) – The input tensor. The rank must be at least 2.

  • diagonal (int, optional) – The diagonal specified of 2-D tensor. Default 0 represents the main diagonal.

Returns

Tensor

Supported Platforms:

Ascend GPU CPU

Examples

>>> 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]]])