mindspore.ops.tril
- mindspore.ops.tril(input, diagonal=0)[source]
Returns the lower triangle part of 'input' (elements that contain the diagonal and below), and set the other elements to zeros.
- Parameters
- Returns
Tensor, the same shape and data type as the input x.
- Raises
TypeError – If x is not a Tensor.
TypeError – If diagonal is not an int.
TypeError – If the type of x is neither number nor bool.
ValueError – If the rank of x is less than 2.
- Supported Platforms:
Ascend
GPU
CPU
Examples
>>> import numpy as np >>> from mindspore import Tensor, ops >>> x = Tensor(np.array([[ 1, 2, 3, 4], ... [ 5, 6, 7, 8], ... [10, 11, 12, 13], ... [14, 15, 16, 17]])) >>> result = ops.tril(x) >>> print(result) [[ 1 0 0 0] [ 5 6 0 0] [10 11 12 0] [14 15 16 17]] >>> x = Tensor(np.array([[ 1, 2, 3, 4], ... [ 5, 6, 7, 8], ... [10, 11, 12, 13], ... [14, 15, 16, 17]])) >>> result = ops.tril(x, diagonal=1) >>> print(result) [[ 1 2 0 0] [ 5 6 7 0] [10 11 12 13] [14 15 16 17]] >>> x = Tensor(np.array([[ 1, 2, 3, 4], ... [ 5, 6, 7, 8], ... [10, 11, 12, 13], ... [14, 15, 16, 17]])) >>> result = ops.tril(x, diagonal=-1) >>> print(result) [[ 0 0 0 0] [ 5 0 0 0] [10 11 0 0] [14 15 16 0]]