Learn practical skills, build real-world projects, and advance your career
Created 4 years ago
Assignment 1
Common mathematical operations in PyTorch
This notebook provides a short introduction about the following functions in PyTorch:
- torch.max()
- torch.mean()
- torch.log()
- torch.zeros()
- torch.t()
# Import torch and other required modules
import torch
Function 1 - torch.max ()
This function takes a tensor as the input and returns the maximum value of all elements in the input tensor.
# Example 1 - working
# creating a tensor
a = torch.tensor([[1, 3], [1,5]])
# Using the max function
torch.max(a)
tensor(5)
The torch.max() function is used to find the maximum element in the input tensor which is 5 as indicated in the results.