mindspore.ops.Tril
- class mindspore.ops.Tril(diagonal=0)[source]
Returns the lower triangular portion of the 2-D matrix or the set of matrices in a batch. The remaining elements of the resulting Tensor are assigned a value of 0. The lower triangular section of the matrix comprises of the elements present on and below the main diagonal.
Warning
This is an experimental API that is subject to change or deletion.
- Parameters
diagonal (int, optional) – An optional attribute indicates the diagonal to consider, default: 0, indicating the main didiagonal.
- Inputs:
x (Tensor) - A Tensor with shape \((x_1, x_2, ..., x_R)\). The rank must be at least 2. Supporting all number types including bool.
- Outputs:
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
>>> x = Tensor(np.array([[ 1, 2, 3, 4], ... [ 5, 6, 7, 8], ... [10, 11, 12, 13], ... [14, 15, 16, 17]])) >>> tril = ops.Tril() >>> result = 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]])) >>> tril = ops.Tril(diagonal=1) >>> result = tril(x) >>> 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]])) >>> tril = ops.Tril(diagonal=-1) >>> result = tril(x) >>> print(result) [[ 0 0 0 0] [ 5 0 0 0] [10 11 0 0] [14 15 16 0]]