mindspore.ops.TriuIndices

class mindspore.ops.TriuIndices(row, col, offset=0, dtype=mstype.int32)[source]

Calculates the indices of the upper triangular elements in a row * col matrix and returns them as a 2-by-N Tensor.

Warning

This is an experimental API that is subject to change or deletion.

Refer to mindspore.ops.triu_indices() for more details.

Parameters
  • row (int) – number of rows in the 2-D matrix.

  • col (int) – number of columns in the 2-D matrix.

  • offset (int, optional) – diagonal offset from the main diagonal. Default: 0.

  • dtype (mindspore.dtype, optional) – The specified type of output tensor. An optional data type of mstype.int32 and mstype.int64. Default: mstype.int32.

Outputs:
  • y (Tensor) - indices of the elements in lower triangular part of matrix. The type specified by dtype. The shape of output is \((2, tril\_size)\), where \(tril\_size\) is the number of elements in the lower triangular matrix.

Supported Platforms:

Ascend GPU CPU

Examples

>>> net = ops.TriuIndices(5, 4, 2, mstype.int64)
>>> output = net()
>>> print(output)
[[0 0 1]
 [2 3 3]]
>>> print(output.dtype)
Int64