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.]])

 

posted on 2021-08-11 09:11  那抹阳光1994  阅读(405)  评论(0编辑  收藏  举报

导航