mindspore.nn.Triu
- class mindspore.nn.Triu[source]
Returns a tensor with elements below the kth diagonal zeroed.
- Inputs:
x (Tensor) - The input tensor.
k (Int) - The index of diagonal. Default: 0
- Outputs:
Tensor, has the same type as input x.
- Raises
TypeError – If k is not an int.
ValueError – If length of shape of x is less than 1.
- Supported Platforms:
Ascend
GPU
CPU
Examples
>>> x = Tensor(np.array([[1, 2], [3, 4]])) >>> triu = nn.Triu() >>> result = triu(x) >>> print(result) [[1 2] [0 4]]