torch.eye

torch.eye

torch.eye(n, m=None, out=None)

返回一个2维张量,对角线位置全1,其它位置全0

  • n (int ) – 行数
  • m (int, optional) – 列数.如果为None,则默认为n
  • out (Tensor, optinal) - Output tensor

返回值: 对角线位置全1,其它位置全0的2维张量

返回值类型: Tensor

例子:

>>> torch.eye(3)

1 0 0

0 1 0

0 0 1

[torch.FloatTensor of size 3x3]

猜你喜欢

转载自www.cnblogs.com/btschang/p/10300727.html