mindspore.ops.triu_indices
- mindspore.ops.triu_indices(row, col, offset=0, *, dtype=mstype.int64)[source]
Return a 2-by-N tensor containing the indices of the upper 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:
Ascend
GPU
CPU
Examples
>>> import mindspore >>> # case 1: By default, offset=0, all elements on and below the main diagonal are retained. >>> mindspore.ops.triu_indices(3, 2, 0) Tensor(shape=[2, 3], dtype=Int64, value= [[0, 0, 1], [0, 1, 1]]) >>> >>> # case 2: If offset=-1, the indices on and above the first sub-diagonal below the main diagonal are returned. >>> mindspore.ops.triu_indices(3, 2, -1) Tensor(shape=[2, 5], dtype=Int64, value= [[0, 0, 1, 1, 2], [0, 1, 0, 1, 1]])