mindspore.ops.tril_indices
- mindspore.ops.tril_indices(row, col, offset=0, *, dtype=mstype.int64)[source]
Calculates the indices of the lower triangular elements in a row * col matrix and returns them as a 2-by-N Tensor. The first row of the Tensor contains row coordinates, and the second row contains column coordinates. The coordinates are sorted by row and then by column.
The lower triangular part of the matrix consists of all elements on and below the diagonal.
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. Default: mindspore.int64.- Returns
y (Tensor) - indices of the elements in lower triangular part of matrix. The type is specified by dtype. The shape of output is \((2, tril\_size)\), where \(tril\_size\) is the number of elements in the lower triangular matrix.
- Raises
TypeError – If row, col or offset is not an int.
TypeError – If dtype is neither int32 nor int64.
ValueError – If row or col < 0.
- Supported Platforms:
Ascend
GPU
CPU
Examples
>>> output = ops.tril_indices(4, 3, -1, mindspore.int64) >>> print(output) [[1 2 2 3 3 3] [0 0 1 0 1 2]] >>> print(output.dtype) Int64