Shahid Akhtar Khan has Published 216 Articles

How to perform element-wise subtraction on tensors in PyTorch?

Shahid Akhtar Khan

Shahid Akhtar Khan

Updated on 06-Nov-2021 09:47:54

4K+ Views

To perform element-wise subtraction on tensors, we can use the torch.sub() method of PyTorch. The corresponding elements of the tensors are subtracted. We can subtract a scalar or tensor from another tensor. We can subtract a tensor from a tensor with same or different dimension. The dimension of the final ... Read More

How to perform element-wise addition on tensors in PyTorch?

Shahid Akhtar Khan

Shahid Akhtar Khan

Updated on 06-Nov-2021 09:45:52

8K+ Views

We can use torch.add() to perform element-wise addition on tensors in PyTorch. It adds the corresponding elements of the tensors. We can add a scalar or tensor to another tensor. We can add tensors with same or different dimensions. The dimension of the final tensor will be same as the ... Read More

How to resize a tensor in PyTorch?

Shahid Akhtar Khan

Shahid Akhtar Khan

Updated on 06-Nov-2021 09:44:33

6K+ Views

To resize a PyTorch tensor, we use the .view() method. We can increase or decrease the dimension of the tensor, but we have to make sure that the total number of elements in a tensor must match before and after the resize.StepsImport the required library. In all the following Python ... Read More

How to access the metadata of a tensor in PyTorch?

Shahid Akhtar Khan

Shahid Akhtar Khan

Updated on 06-Nov-2021 09:39:31

567 Views

We access the size (or shape) of a tensor and the number of elements in the tensor as the metadata of the tensor. To access the size of a tensor, we use the .size() method and the shape of a tensor is accessed using .shape.Both .size() and .shape produce the ... Read More

How to access and modify the values of a Tensor in PyTorch?

Shahid Akhtar Khan

Shahid Akhtar Khan

Updated on 06-Nov-2021 09:35:20

9K+ Views

We use Indexing and Slicing to access the values of a tensor.Indexing is used to access the value of a single element of the tensor, whereasSlicing is used to access the values of a sequence of elements.We use the assignment operator to modify the values of a tensor. Assigning new ... Read More

How to convert an image to a PyTorch Tensor?

Shahid Akhtar Khan

Shahid Akhtar Khan

Updated on 06-Nov-2021 09:31:58

13K+ Views

A PyTorch tensor is an n-dimensional array (matrix) containing elements of a single data type. A tensor is like a numpy array. The difference between numpy arrays and PyTorch tensors is that the tensors utilize the GPUs to accelerate the numeric computations. For the accelerated computations, the images are converted ... Read More

Advertisements