- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Shahid Akhtar Khan has Published 216 Articles
![Shahid Akhtar Khan](https://www.tutorialspoint.com/assets/profiles/394091/profile/60_2508042-1636180991.jpg)
Shahid Akhtar Khan
6K+ Views
To check if an object is a tensor or not, we can use the torch.is_tensor() method. It returns True if the input is a tensor; False otherwise.Syntaxtorch.is_tensor(input)Parametersinput – The object to be checked, if it is a tensor or not .OutputIt returns True if the input is a tensor; else ... Read More
![Shahid Akhtar Khan](https://www.tutorialspoint.com/assets/profiles/394091/profile/60_2508042-1636180991.jpg)
Shahid Akhtar Khan
5K+ Views
The use of "with torch.no_grad()" is like a loop where every tensor inside the loop will have requires_grad set to False. It means any tensor with gradient currently attached with the current computational graph is now detached from the current graph. We no longer be able to compute the gradients ... Read More
![Shahid Akhtar Khan](https://www.tutorialspoint.com/assets/profiles/394091/profile/60_2508042-1636180991.jpg)
Shahid Akhtar Khan
3K+ Views
The backward() method is used to compute the gradient during the backward pass in a neural network.The gradients are computed when this method is executed.These gradients are stored in the respective variables.The gradients are computed with respect to these variables, and the gradients are accessed using .grad.If we do not ... Read More
![Shahid Akhtar Khan](https://www.tutorialspoint.com/assets/profiles/394091/profile/60_2508042-1636180991.jpg)
Shahid Akhtar Khan
2K+ Views
A contiguous tensor is a tensor whose elements are stored in a contiguous order without leaving any empty space between them. A tensor created originally is always a contiguous tensor. A tensor can be viewed with different dimensions in contiguous manner.A transpose of a tensor creates a view of the ... Read More
![Shahid Akhtar Khan](https://www.tutorialspoint.com/assets/profiles/394091/profile/60_2508042-1636180991.jpg)
Shahid Akhtar Khan
7K+ Views
To transpose a tensor, we need two dimensions to be transposed. If a tensor is 0-D or 1-D tensor, the transpose of the tensor is same as is. For a 2-D tensor, the transpose is computed using the two dimensions 0 and 1 as transpose(input, 0, 1).SyntaxTo find the transpose ... Read More
![Shahid Akhtar Khan](https://www.tutorialspoint.com/assets/profiles/394091/profile/60_2508042-1636180991.jpg)
Shahid Akhtar Khan
1K+ Views
The rank of a matrix can be obtained using torch.linalg.matrix_rank(). It takes a matrix or a batch of matrices as the input and returns a tensor with rank value(s) of the matrices. torch.linalg module provides us many linear algebra operations.Syntaxtorch.linalg.matrix_rank(input)where input is the 2D tensor/matrix or batch of matrices.StepsWe could ... Read More
![Shahid Akhtar Khan](https://www.tutorialspoint.com/assets/profiles/394091/profile/60_2508042-1636180991.jpg)
Shahid Akhtar Khan
1K+ Views
To find the exponential of the elements of an input tensor, we can apply Tensor.exp() or torch.exp(input). Here, input is the input tensor for which the exponentials are computed. Both the methods return a new tensor with the exponential values of the elements of the input tensor.SyntaxTensor.exp()ortorch.exp(input) StepsWe could use ... Read More
![Shahid Akhtar Khan](https://www.tutorialspoint.com/assets/profiles/394091/profile/60_2508042-1636180991.jpg)
Shahid Akhtar Khan
380 Views
We use the torch.log2() method to compute logarithm to the base 2 of the elements of a tensor. It returns a new tensor with the logarithm values of the elements of the original input tensor. It takes a tensor as the input parameter and outputs a tensor.Syntaxtorch.log2(input)where input is a ... Read More
![Shahid Akhtar Khan](https://www.tutorialspoint.com/assets/profiles/394091/profile/60_2508042-1636180991.jpg)
Shahid Akhtar Khan
11K+ Views
Tensor.detach() is used to detach a tensor from the current computational graph. It returns a new tensor that doesn't require a gradient.When we don't need a tensor to be traced for the gradient computation, we detach the tensor from the current computational graph.We also need to detach a tensor when ... Read More
![Shahid Akhtar Khan](https://www.tutorialspoint.com/assets/profiles/394091/profile/60_2508042-1636180991.jpg)
Shahid Akhtar Khan
11K+ Views
To compute the gradients, a tensor must have its parameter requires_grad = true. The gradients are same as the partial derivatives.For example, in the function y = 2*x + 1, x is a tensor with requires_grad = True. We can compute the gradients using y.backward() function and the gradient can ... Read More