mindspore.ops.tril_indices

查看源文件
mindspore.ops.tril_indices(row, col, offset=0, *, dtype=mstype.int64)[源代码]

返回一个二维的tensor,包含 row * col 矩阵的下三角元素的索引。第一行是所有索引的行坐标,第二行是所有索引的列坐标。 坐标先按行排序,后按列排序。

说明

在CUDA上运行时, row * col 必须小于2^59,以防止计算时溢出。

参数:
  • row (int) - 二维tensor的行数。

  • col (int) - 二维tensor的列数。

  • offset (int, 可选) - 对角线偏移量。默认 0

    • offset 是正整数时,对角线向上方偏移。

    • offset 是负整数时,对角线向下方偏移。

关键字参数:
  • dtype (mindspore.dtype, 可选) - 指定数据类型,支持 mstype.int32mstype.int64 ,默认 mstype.int64

返回:

Tensor

支持平台:

Ascend GPU CPU

样例:

>>> 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]])