- 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
1K+ Views
To sort the elements of a tensor in PyTorch, we can use the torch.sort() method. This method returns two tensors. The first tensor is a tensor with sorted values of the elements and the second tensor is a tensor of indices of elements in the original tensor. We can compute ... Read More
![Shahid Akhtar Khan](https://www.tutorialspoint.com/assets/profiles/394091/profile/60_2508042-1636180991.jpg)
Shahid Akhtar Khan
1K+ Views
To compute the logarithm of elements of a tensor in PyTorch, we use the torch.log() method. It returns a new tensor with the natural logarithm values of the elements of the original input tensor. It takes a tensor as the input parameter and outputs a tensor.StepsImport the required library. In ... Read More
![Shahid Akhtar Khan](https://www.tutorialspoint.com/assets/profiles/394091/profile/60_2508042-1636180991.jpg)
Shahid Akhtar Khan
13K+ Views
A PyTorch tensor is homogenous, i.e., all the elements of a tensor are of the same data type. We can access the data type of a tensor using the ".dtype" attribute of the tensor. It returns the data type of the tensor.StepsImport the required library. In all the following Python ... Read More
![Shahid Akhtar Khan](https://www.tutorialspoint.com/assets/profiles/394091/profile/60_2508042-1636180991.jpg)
Shahid Akhtar Khan
4K+ Views
To squeeze a tensor, we use the torch.squeeze() method. It returns a new tensor with all the dimensions of the input tensor but removes size 1. For example, if the shape of the input tensor is (M ☓ 1 ☓ N ☓ 1 ☓ P), then the squeezed tensor will ... Read More
![Shahid Akhtar Khan](https://www.tutorialspoint.com/assets/profiles/394091/profile/60_2508042-1636180991.jpg)
Shahid Akhtar Khan
1K+ Views
The histogram of a tensor is computed using torch.histc(). It returns a histogram represented as a tensor. It takes four parameters: input, bins, min and max. It sorts the elements into equal width bins between min and max. It ignores the elements smaller than the min and greater than the ... Read More
![Shahid Akhtar Khan](https://www.tutorialspoint.com/assets/profiles/394091/profile/60_2508042-1636180991.jpg)
Shahid Akhtar Khan
2K+ Views
RGB images have three channels, Red, Green, and Blue. We need to compute the mean of the image pixel values across these image channels. For this purpose, we use the method torch.mean(). But the input parameter to this method is a PyTorch tensor. So, we first convert the image to ... Read More
![Shahid Akhtar Khan](https://www.tutorialspoint.com/assets/profiles/394091/profile/60_2508042-1636180991.jpg)
Shahid Akhtar Khan
739 Views
PyTorch provides a method torch.kthvalue() to find the k-th element of a tensor. It returns the value of the k-th element of tensor sorted in ascending order, and the index of the element in the original tensor.torch.topk() method is used to find the top "k" elements. It returns the top ... Read More
![Shahid Akhtar Khan](https://www.tutorialspoint.com/assets/profiles/394091/profile/60_2508042-1636180991.jpg)
Shahid Akhtar Khan
5K+ Views
A PyTorch tensor is like a numpy array. The only difference is that a tensor utilizes the GPUs to accelerate numeric computations. The mean of a tensor is computed using the torch.mean() method. It returns the mean value of all the elements in the input tensor. We can also compute ... Read More
![Shahid Akhtar Khan](https://www.tutorialspoint.com/assets/profiles/394091/profile/60_2508042-1636180991.jpg)
Shahid Akhtar Khan
5K+ Views
To perform element-wise division on two tensors in PyTorch, we can use the torch.div() method. It divides each element of the first input tensor by the corresponding element of the second tensor. We can also divide a tensor by a scalar. A tensor can be divided by a tensor with ... Read More
![Shahid Akhtar Khan](https://www.tutorialspoint.com/assets/profiles/394091/profile/60_2508042-1636180991.jpg)
Shahid Akhtar Khan
13K+ Views
torch.mul() method is used to perform element-wise multiplication on tensors in PyTorch. It multiplies the corresponding elements of the tensors. We can multiply two or more tensors. We can also multiply scalar and tensors. Tensors with same or different dimensions can also be multiplied. The dimension of the final tensor ... Read More