Python Pytorch eye() method Last Updated : 22 Apr, 2020 Summarize Comments Improve Suggest changes Share Like Article Like Report PyTorch is an open-source machine learning library developed by Facebook. It is used for deep neural network and natural language processing purposes. The function 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) Parameters: n: the number of rows m: the number of columns. Default - n out (Tensor, optional): the output tensor Return type: A 2-D tensor Code #1: Python3 # Importing the PyTorch library import torch # Applying the eye function and # storing the resulting tensor in 'a' a = torch.eye(3, 4) print("a = ", a) b = torch.eye(3, 3) print("b = ", b) c = torch.eye(5, 1) print("c = ", c) Output: 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.]]) Comment More infoAdvertise with us Next Article Pgmagick edge() method - Python S sanskar27jain Follow Improve Article Tags : Python Python-PyTorch Practice Tags : python Similar Reads Python | sympy.eye() method With the help of sympy.eye() method, we can find the identity matrix by using sympy.eye() method. Syntax : sympy.eye() Return : Return an identity matrix. Example #1 : In this example, we can see that by using sympy.eye() method, we are able to find identity matrix having dimension nxn, where n will 1 min read RandomResizedCrop() Method in Python PyTorch In this article, we are going to discuss RandomResizedCrop() method in Pytorch using Python. RandomResizedCrop() method RandomResizedCrop() method of torchvision.transforms module is used to crop a random area of the image and resized this image to the given size. This method accepts both PIL Image 2 min read RandomVerticalFlip() Method in Python PyTorch In this article, we are going to discuss RandomVerticalFlip() Method in PyTorch using Python. RandomVerticalFlip() Method RandomVerticalFlip() method of torchvision.transforms module is used to vertically flip the image at a random angle with a given probability.  This accepts a PIL image and a ten 2 min read How Does the "View" Method Work in Python PyTorch? PyTorch, a popular open-source machine learning library, is known for its dynamic computational graphs and intuitive interface, particularly when it comes to tensor operations. One of the most commonly used tensor operations in PyTorch is the .view() function. If you're working with PyTorch, underst 5 min read Pgmagick edge() method - Python The edge() function is an inbuilt function in the Pgmagick library which is used to apply a convolution filter to detect edges. Syntax: edge(radius) Parameters: This function accepts single parameter as mentioned above and defined below: radius: This parameter stores the aperture of detection filter 1 min read Python - tensorflow.eye() TensorFlow is open-source Python library designed by Google to develop Machine Learning models and deep learning  neural networks. tensorflow.eye() is used to generate identity matrix. Syntax: tensorflow.eye( num_rows, num_columns, batch_shape, dtype, name) Parameters: num_rows: It is int32 scalar 2 min read Like