Learn practical skills, build real-world projects, and advance your career
Updated 3 years ago
Let's Explore PyTorch Tensor Functions
Introduction:
An short introduction about PyTorch and about the chosen functions.
PyTorch is a tensor library for deep learning using GPUs and CPU.It is a different kind of deep learning library (dynamic, rather than static).
- TORCH.POW
- TORCH.DIAGFLAT
- TORCH.BINCOUNT
- TORCH.MAX
- TORCH.FMOD
Before we begin, let's install and import PyTorch
# Import torch and other required modules
import torch
Function 1 - torch.pow (input,exponent)
Used to calculate powers where atleast one of the input or exponent to be a tensor
# Example 1 - working
a = torch.arange(1., 10.)
cubes_a = torch.pow(a,3)
print(len(a))
print(a)
cubes_a
9
tensor([1., 2., 3., 4., 5., 6., 7., 8., 9.])
tensor([ 1., 8., 27., 64., 125., 216., 343., 512., 729.])
torch.arange creates a 1-D tensor with default gap of 1 between each pair of adjacent points.Here 1 to 9 excluding the end point 10.
torch.pow calculates the power of each element in input tensor with exponent and returns a tensor