tril_indices¶
- paddle. tril_indices ( row, col, offset=0, dtype='int64' ) [source]
-
Return the indices of the lower triangular part of the 2-D matrix whose row and col is known. Indices are ordered based on row and then columns. The lower triangular part of the matrix is defined as the elements on and below the diagonal.
- Parameters
-
row (int) – The input x which is a int number describe the number of row of the matrix.
col (int) – The input x which is a int number describe the number of col of the matrix.
offset (int, optional) –
The offset to consider, default value is 0.
If offset = 0, all elements on and below the main diagonal are retained.
If offset > 0, include just as many diagonals above the main diagonal.
If offset < 0, excludes just as many diagonals below the main diagonal.
dtype (int, optional) – the data type of the output tensor, can be int32, int64.
- Returns
-
Results of the indices of lower triangular part of a row * col matrix, where the first row contains row coordinates of and the second row contains column coordinates.
- Return type
-
Tensor
Examples
>>> import paddle >>> # example 1, default offset value >>> data1 = paddle.tril_indices(4,4,0) >>> print(data1) Tensor(shape=[2, 10], dtype=int64, place=Place(cpu), stop_gradient=True, [[0, 1, 1, 2, 2, 2, 3, 3, 3, 3], [0, 0, 1, 0, 1, 2, 0, 1, 2, 3]]) >>> # example 2, positive offset value >>> data2 = paddle.tril_indices(4,4,2) >>> print(data2) Tensor(shape=[2, 15], dtype=int64, place=Place(cpu), stop_gradient=True, [[0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3], [0, 1, 2, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3]]) >>> # example 3, negative offset value >>> data3 = paddle.tril_indices(4,4,-1) >>> print(data3) Tensor(shape=[2, 6], dtype=int64, place=Place(cpu), stop_gradient=True, [[1, 2, 2, 3, 3, 3], [0, 0, 1, 0, 1, 2]])