Returns a 2-D tensor with ones on the diagonal and zeros elsewhere.
tch_eye(n, m = n, dtype = NULL, layout = NULL, device = NULL, requires_grad = FALSE)
n | integer. The number of rows. |
---|---|
m | (optional) integer. The number of columns with default being n. |
dtype | the desired data type of returned tensor. Default: if |
device | the desired device of returned tensor. Default: if |
requires_grad | If autograd should record operations on the
returned tensor. Default: |
the | desired layout of returned Tensor. Default: 'strided' |
tch_eye(3)#> tensor #> 1 0 0 #> 0 1 0 #> 0 0 1 #> [ Variable[CPUFloatType]{3,3} ]tch_eye(2, 4)#> tensor #> 1 0 0 0 #> 0 1 0 0 #> [ Variable[CPUFloatType]{2,4} ]