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) - The input tensor with shape \((M, N, *)\) where \(*\) means any number of additional dimensions.
- 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.
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]])) >>> 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]]