Different PyTorch’s tensor functions

Aditya N
1 min readMay 29, 2020

lets’s see 5 different PyTorch’s built in functions in this article,PyTorch is Developed by Facebook AI Research lab, is widely used as a deep learning framework for many different reasons ranging from easy to use and learning projects to computer vision applications.

1.Tensor

This function allows us to create the tensor of the desired shape and dimension scalar,vector or matrix.

Example 1
Example 2

2. Diagonal

This function helps in fixing a desired element in the diagonal position of a matrix.to illustrate the below ex we have used ONE’S and ZERO’S functions which will just create matrix of desired shape with 1’s and 0’s respectively.

Example 1
Example 2

3.Reshape

This function helps us to reshape the built matrix into the desired shape of our wish where we use a rand function to create a random function with different values (m*n) where m rows and n columns. which we can reshape into desired shape using the reshape function.

Example 1
Example 2

4. Multiply

As multiplication is one of the important usecase s of tensor PyTorch provides us with a inbuilt multiplication function.

Example

5.Unfold

In this operation where we unfold the matrix into the desired way of our wish where we pass 3 parameters such as (Rows,Columns,fold rate),we use a arange function which is similar to the loop function

Example 1
Example 2

Final Note:

There are various such functions available in PyTorch Documentation ,This is just a gist of it.

Link for the Documentation:

https://pytorch.org/docs/stable/index.html#pytorch-documentation

--

--