pytorch 生成单位张量torch.eye

torch.eye(nm=None*out=Nonedtype=Nonelayout=torch.strideddevice=Nonerequires_grad=False) → Tensor

Returns a 2-D tensor with ones on the diagonal and zeros elsewhere.

>>> torch.eye(3)
tensor([[ 1.,  0.,  0.],
        [ 0.,  1.,  0.],
        [ 0.,  0.,  1.]])
快去成为你想要的样子!
原文地址:https://www.cnblogs.com/jiangkejie/p/15126765.html