Learn practical skills, build real-world projects, and advance your career
Updated 4 years ago
PYTORCH TORCH FUNCTIONS INTRODUCTION
TORCH
The torch package contains data structures for multi-dimensional tensors and mathematical operations over these are defined. Additionally, it provides many utilities for efficient serializing of Tensors and arbitrary types, and other useful utilities.
- logspace
- linespace
- clamp
- torch.where(condition, x, y)
- function 5
# Import torch and other required modules
import torch
Function 1 - torch.linspace(..)
https://pytorch.org/docs/master/generated/torch.linspace.html
function definitions
- torch.linspace(start, end, steps=100, out=None, dtype=None, layout=torch.strided, device=None, requires_grad=False)
# Example 1 - working (change this)
print(torch.linspace(1, 10, steps=5))
tensor([ 1.0000, 3.2500, 5.5000, 7.7500, 10.0000])
- linspace creates a tensor with number of elements equal to number of steps and the elements in the tensor are equispaced between the start and the stop i.e. for this example numbers start from 1 upto 10 in 5 steps so each step size is (10-1)/(5-1) = 2.25