Sitemap

PyTorch

1 min readJun 12, 2020

--

Here we will discuss the torch.Tensor and some basic functions

Why PyTorch?

There are only a few major deep learning frameworks; and among them, PyTorch is emerging as a winner. PyTorch is an open-source machine learning library inspired by Torch.

Here are some reason to move towards PyTorch

  1. PyTorch is based on Python
  2. A dynamic approach to graph computation
  3. Fast and easy to train
  4. Increase productivity
  5. Simple to learn

Now we will discuss 5 basic functions of PyTorch

  • torch.shape()
  • torch.dim()
  • torch.tril()
  • torch.lerp()
  • torch.clamp()

Now we will work with these functions one by one

Import torch and other required modules
  1. torch.shape():

We will create a tensor array

we have to create a tensor array
Hence shape of x in terms of dimensions

2. torch.dim():

Get Praveen kumar’s stories in your inbox

Join Medium for free to get updates from this writer.

This function will tell us the shape is lie in which dimension i.e. of 1-Dimension, 2-Dimension or n-Dimension

Hence the dimension of the array is 2

3. torch.tril():

Note: The error occured because of the dimension of the array is under range.
therefor it requires the atleast 2-D array to execute the tril function

4. torch.lerp():

5.torch.clamp():

This function will Clamp all elements in input into the range 
[ min, max ] and return a resulting tensor

Conclusion: Therefore above are few functions of PyTorch and there are n-numbers of functions and we can do much more with them

Reference Link: Documentation for torch.Tensor: https://pytorch.org/docs/stable/tensors.html
AI work: https://www.aiworkbox.com/
Discussion forum of PyTorch: https://discuss.pytorch.org/
Youtube Lecture: https://youtu.be/vo_fUOk-IKk

--

--