Returns a partial view of input with the its diagonal elements with respect to dim1 and dim2 appended as a dimension at the end of the shape.

tch_diagonal(x, offset = 0, dim1 = 0, dim2 = 1)

Arguments

x

tensor object

offset

which diagonal to consider

dim1

first dimension with respect to which to take diagonal

dim2

second dimension with respect to which to take diagonal

Details

The argument offset controls which diagonal to consider:

If offset = 0, it is the main diagonal. If offset > 0, it is above the main diagonal. If offset < 0, it is below the main diagonal.

See also

tch_diag() tch_diagonal()

Examples

tch_diagonal(tensor(matrix(1:4, 2, 2)))
#> tensor #> 1 #> 4 #> [ Variable[CPUIntType]{2} ]