eye

dragon.vm.torch.eye(
  n,
  m=None,
  out=None,
  dtype='float32',
  device=None,
  requires_grad=False
)[source]

Return a tensor constructed as the identity matrix.

\[\text{out} \leftarrow \text{diag}(1, 1, ..., 1) \]

The rows and cols of matrix are determined by n and m:

print(torch.eye(2))  # [[1., 0.], [0., 1.]]
print(torch.eye(2, 3))  # [[1., 0., 0.], [0., 1., 0.]]
Parameters:
  • n (int) – The number output rows.
  • m (int, optional) – The number output cols.
  • out (dragon.vm.torch.Tensor, optional) – The optional output tensor.
  • dtype (str, optional, default='float32') – The optional data type.
  • device (dragon.vm.torch.device, optional) – The optional device of returned tensor.
  • requires_grad (bool, optional, default=False) – True to record gradient for returned tensor.
Returns:

dragon.vm.torch.Tensor – The output tensor.