PyTorch is an open-source machine learning library developed by Facebook. It is used for deep neural network and natural language processing purposes.
torch.eye() returns a returns a 2-D tensor of size n*m with ones on the diagonal and zeros elsewhere.
Syntax: torch.eye(n, m, out=None)
n: the number of rows
m: the number of columns. Default – n
out (Tensor, optional): the output tensor
Return type: A 2-D tensor
a = tensor([[1., 0., 0., 0.], [0., 1., 0., 0.], [0., 0., 1., 0.]]) b = tensor([[1., 0., 0.], [0., 1., 0.], [0., 0., 1.]]) c = tensor([[1.], [0.], [0.], [0.], [0.]])
Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.
To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course. And to begin with your Machine Learning Journey, join the Machine Learning – Basic Level Course