# Math operations in PyTorch

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

%[https://jovian.ml/dx4iot/01-tensor-operations/v/16&cellId=1]

%[https://jovian.ml/dx4iot/01-tensor-operations/v/16&cellId=2]

## 1. torch.abs(input)
Calculate the absolute value of the input

%[https://jovian.ml/dx4iot/01-tensor-operations/v/16&cellId=4]

**Explanation about Example 1:
**
In the above example when we apply torch.abs(t1) it changes the list item to its absolute values.

%[https://jovian.ml/dx4iot/01-tensor-operations/v/16&cellId=6]

%[https://jovian.ml/dx4iot/01-tensor-operations/v/16&cellId=12]

## 2. torch.div(input)

Divide each element with their corresponding pair of an element.

%[https://jovian.ml/dx4iot/01-tensor-operations/v/16&cellId=9]

**Explanation about Example 1:
**
In the above example, we use torch.div() to divide each element with its corresponding pair of an element.

%[https://jovian.ml/dx4iot/01-tensor-operations/v/16&cellId=11]

%[https://jovian.ml/dx4iot/01-tensor-operations/v/16&cellId=12]

## 3. torch.frac(input)

torch.frac() calculates the fractional portion of the input

%[https://jovian.ml/dx4iot/01-tensor-operations/v/16&cellId=14]

**Explanation about Example 1:
**
In the above example, we use torch.frac() computes the fractional portion of each element of new_frac

%[https://jovian.ml/dx4iot/01-tensor-operations/v/16&cellId=16]

%[https://jovian.ml/dx4iot/01-tensor-operations/v/16&cellId=17]

## 4. torch.log10(input)

It calculates the log to the base 10 of the input and returns a new tensor.

%[https://jovian.ml/dx4iot/01-tensor-operations/v/16&cellId=19]

**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

%[https://jovian.ml/dx4iot/01-tensor-operations/v/16&cellId=20]

%[https://jovian.ml/dx4iot/01-tensor-operations/v/16&cellId=22]

## 5. torch.neg(input)

It returns a tensor with a negative of the elements of the input.

%[https://jovian.ml/dx4iot/01-tensor-operations/v/16&cellId=24]

**Explanation about Example 1:
**
In the above example we use torch.neg() to calculate the negative of the elements of ret_neg

%[https://jovian.ml/dx4iot/01-tensor-operations/v/16&cellId=26]

%[https://jovian.ml/dx4iot/01-tensor-operations/v/16&cellId=27]


## 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








