Learn practical skills, build real-world projects, and advance your career

SOME OF THE BASIC TENSOR FUNCTIONS

PyTorch is an open source machine learning library based on the Torch library, used for applications such as computer vision and natural language processing, primarily developed by Facebook's AI Research lab. It is free and open-source software released under the Modified BSD license.

following tensor functions are explained in this notebook.

  • torch.range
  • torch.linspace
  • torch.log
  • torch.reshape
  • torch.mean
# Import torch and other required modules
import torch

Function 1 -torch.range(start=0, end, step=1, out=None, dtype=None, layout=torch.strided, device=None, requires_grad=False)

some parameters:

1)start(float) - the starting value for the set of points(default=0.)
2)end(float) -the ending value for the set of points
3)step(float) -the gap between each pair of adjacent points(default=1.)
4)out(Tensor) -the output tensor (optional)
5)requires_grad(bool) -if autograd should record operations on the returned tensor (Defalt=False)

what the function does:
  1. Returns a 1D tensor of size (((end-start)/step)+1)
  2. Values start from the given start value
  3. Values end at the given end value
  4. next_value = previous_value + step
# Example 1 - working
torch.range(1 ,5)
/srv/conda/envs/notebook/lib/python3.7/site-packages/ipykernel_launcher.py:1: UserWarning: torch.range is deprecated in favor of torch.arange and will be removed in 0.5. Note that arange generates values in [start; end), not [start; end]. """Entry point for launching an IPython kernel.
tensor([1., 2., 3., 4., 5.])