mindspore.ops.tril_indices
- mindspore.ops.tril_indices(row, col, offset=0, *, dtype=mstype.int64)[source]
Return a 2-by-N tensor containing the indices of the lower triangular elements of a row * col matrix. The first row of the Tensor contains row coordinates, and the second row contains column coordinates. The coordinates are sorted by rows and then columns.
Note
When running on CUDA, row * col must be less than 2^59 to prevent overflow during calculation.
- Parameters
- Keyword Arguments
dtype (
mindspore.dtype, optional) – The specified type of output tensor. An optional data type of mindspore.int32 and mindspore.int64. Defaultmstype.int64.- Returns
Tensor
- Supported Platforms:
AscendGPUCPU
Examples
>>> import mindspore >>> # case 1: By default, offset=0, all elements on and below the main diagonal are retained. >>> mindspore.ops.tril_indices(3, 2, 0) Tensor(shape=[2, 5], dtype=Int64, value= [[0, 1, 1, 2, 2], [0, 0, 1, 0, 1]]) >>> >>> # case 2: Offset=1, the indices on and below the first sub-diagonal above the main diagonal are returned. >>> mindspore.ops.tril_indices(3, 2, 1) Tensor(shape=[2, 6], dtype=Int64, value= [[0, 0, 1, 1, 2, 2], [0, 1, 0, 1, 0, 1]]) >>> >>> # case 3: Offset=-1, the indices on and below the first sub-diagonal below the main diagonal are returned. >>> mindspore.ops.tril_indices(3, 2, -1) Tensor(shape=[2, 3], dtype=Int64, value= [[1, 2, 2], [0, 0, 1]])