Learn practical skills, build real-world projects, and advance your career
Created 4 years ago
Deep Learning with PyTorch
Assignment1 - All about torch.Tensor
PyTorch is an optimized tensor library for deep learning using GPUs and CPUs.
The torch package contains data structures for multi-dimensional tensors and mathematical operations. Additionally, it provides many utilities for efficient serializing of Tensors and arbitrary types, and other useful utilities.
A torch.Tensor is a multi-dimensional matrix containing elements of a single data type. Torch defines nine CPU tensor types and nine GPU tensor types.
The following torch.Tensor functions are experimented as part of this assignment:
- torch.abs() : Computes the element-wise absolute value of the given input tensor
- torch.bitwise_and() : Computes the bitwise AND of input and other.
- torch.reshape() : Returns a tensor with the same data and number of elements as input, but with the specified shape.
- torch.unbind() : Removes a tensor dimension.
- torch.take() : Returns a new tensor with the elements of input at the given indices.
# Import torch and other required modules
import torch
Function 1 - torch.abs()
Computes the element-wise absolute value of the given input tensor.
Parameters:
- input(Tensor) : the input tensor
- output(Tensor, Optional) : the output tensor
# Example 1
torch.abs(torch.tensor([-1, -2, 3]))
tensor([1, 2, 3])
# Example 2
torch.abs(torch.tensor([-1, -2, -(-3)]))
tensor([1, 2, 3])