Python | PyTorch atan () method

NumPy | Python Methods and Functions

The torch.atan () function provides support for the inverse tangent function in PyTorch. This gives the output in radians. Input type — tensor, and if the input contains more than one element, the inverse tangent is calculated for each element.

Syntax : torch.atan (x, out = None)

Parameters :
x : Input tensor
name (optional): Output tensor

Return type : A tensor with the same type as that of x.

Code # 1:

# PyTorch library import

import torch

 
# Constant tensor of size 6

a = torch.FloatTensor ([ 1.0 , -  0.5 , 3.4 , 0.2 , 0.0 , - 2 ])

print (a)

 
# Applying the reverse tanning function and
# saving the result to & # 39; b & # 39;

b = torch.atan (a)

print (b)

Exit:

 tensor ([1.0000, -0.5000, 3.4000, 0.2000, 0.0000, -2.0000]) tensor ([0.7854, -0.4636, 1.2847, 0.1974, 0.0000, -1.1071]) 

Code # 2: Vi rendering

# Import PyTorch library

import torch

 
# Import NumPy library

import numpy as np

  
# Import matplotlib.pylot function

import matplotlib.pyplot as plt

 
# Vector size 15 with values ​​from -5 to 5

a = np.linspace ( - 5 , 5 , 15 )

 
# Apply the inverse tangent and
# save the result to & # 39; b & # 39;

b = torch.atan (torch.FloatTensor (a))

  

print (b)

  
# Plot

plt.plot (a, b.numpy (), color = `red` , marker = "o"

plt.title ( "torch.atan"

plt.xlabel ( "X"

plt.ylabel ( "Y"

 
plt.show ()

Exit:

 tensor ([- 1.3734, -1.3416, -1.2978, -1.2341, -1.1342, -0.9601, -0.6202, 0.0000, 0.6202, 0.9601, 1.1342, 1.2341, 1.2978, 1.3416, 1.3734]) 





Get Solution for free from DataCamp guru