Math operations in PyTorch

It has now been seven years since I am exploring my ways in the world of New Age technology. In all these years, what is my favourite thing in the whole world? I would say my keyboard! If it’s a war, I got my code as the skill and my keyboard as the weapon. When I was a kid, I wondered what it would feel like to be a hacker. I kept feeding my curiosity in the bits and pieces. I was getting introduced with new things everyday and over time. All this passion has made me targeted towards my main objective, that is, to learn everything which is out there about computer. For now, I have got a good grip over Python, JavaScript, C and C++. I think the main reason for my motivation is that I strongly believe, if you keep your mind clear and devote yourself to pure learning, there will come a time when your own reality will get surrounded by your self-made uniqueness.
PyTorch is a free and open-source library for training the neural network-based deep learning models. PyTorch contains torch package which provides various functions such as:
- torch.abs(input)
- torch.div(input)
- torch.frac(input)
- torch.log10(input)
- torch.neg(input)
Before we begin, let’s install and import PyTorch
1. torch.abs(input)
Calculate the absolute value of the input
Explanation about Example 1: In the above example when we apply torch.abs(t1) it changes the list item to its absolute values.
2. torch.div(input)
Divide each element with their corresponding pair of an element.
Explanation about Example 1: In the above example, we use torch.div() to divide each element with its corresponding pair of an element.
3. torch.frac(input)
torch.frac() calculates the fractional portion of the input
Explanation about Example 1: In the above example, we use torch.frac() computes the fractional portion of each element of new_frac
4. torch.log10(input)
It calculates the log to the base 10 of the input and returns a new tensor.
Explanation about Example 1:
In the above example, we use torch.log10() to calculate the log to the base 10 of each element of log_cal
5. torch.neg(input)
It returns a tensor with a negative of the elements of the input.
Explanation about Example 1: In the above example we use torch.neg() to calculate the negative of the elements of ret_neg
Conclusion
In this tutorial, we got to know a lot about how to use different math operations like abs(), div(), frac(), log10(), and neg() in PyTorch




