Learn practical skills, build real-world projects, and advance your career
Created 4 years ago
Assignment 1
All About torch.Tensor
PyTorch is an optimized tensor library for deep learning using GPUs and CPUs.
Here are some relevant functions and when to use them.
- torch.tensor.item()
- torch.mean()
- torch.ones()
- torch.argmax()
- torch.eye()
# Import torch and other required modules
import torch
Function 1 - torch.tensor.item()
This function returns a Python number from a tensor containing a single value.
# Example 1 - working
x = torch.tensor(1)
x.item()
1
In this example x is a tensor type with zero dimensions, and x.item() returns a single Python number from it.