How to compute the inverse hyperbolic sine in PyTorch?
In this article, we are going to discuss how to compute the inverse hyperbolic sine in PyTorch.
torch.asinh() method:
The torch.asinh() method is used to compute the inverse hyperbolic sine of each element present in a given input tensor. This method accepts both real and complex-valued as input. It supports input tensors of any dimension. This method returns a tensor after computing the inverse hyperbolic sine of each element in a given input tensor. before moving further let’s see the syntax of this method.
Syntax: torch.asinh(input, *, out=None)
Parameters:
- input: This is our input tensor.
- out (optional) – This is our output tensor.
Return: This method returns a tensor after computing the inverse hyperbolic sine of each element in a given input tensor.
Example 1:
In this example, we are computing the inverse hyperbolic sine for the real-valued 1D tensor.
Python3
import torch
tens = torch.tensor([ 3. , 1.3 , 2. , 2.3 , - 2.3 ])
print ( " Input Tensor - " , tens)
tens_inv_hsin = torch.asinh(tens)
print ( " Computed Inverse Hyperbolic Sine Tensor - " ,
tens_inv_hsin)
|
Output:
Example 2:
In this example, we are computing the inverse hyperbolic sine for the complex-valued 1D tensor.
Python3
import torch
tens = torch.tensor([ 2.1 + 3j , 2. + 2.j , 4. + 2.j , 2.4 + 2.j ])
print ( " Input Tensor - " , tens)
tens_inv_hsin = torch.asinh(tens)
print ( " Computed Inverse Hyperbolic Sine - " ,
tens_inv_hsin)
|
Output:
Example 3:
In this example, we are computing the inverse hyperbolic sine for the real-valued 2D tensor.
Python3
import torch
tens = torch.tensor([[ 1. , 2.3 , 1.3 ],
[ 2.1 , 3. , - 2.3 ],
[ 3.2 , 5.2 , 2.3 ]])
print ( "\n Input Tensor: \n" , tens)
tens_inv_hsin = torch.asinh(tens)
print ( "\n Computed Inverse Hyperbolic Sine: \n " ,
tens_inv_hsin)
|
Output:
Example 4:
In this example, we are computing the inverse hyperbolic sine for the complex-valued 2D tensor.
Python3
import torch
tens = torch.tensor([[ 2.1 + 3j , 2. + 3.j , 3.1 - 3.5j ],
[ 1.3 + 2j , 2.3 - 2.3j , 4. + 3.j ],
[ 3.2 + 5j , 6. + 3.j , 4.2 - 3.2j ]])
print ( "\n Input Tensor: \n" , tens)
tens_inv_hsin = torch.asinh(tens)
print ( "\n Computed Inverse Hyperbolic Sine: \n " ,
tens_inv_hsin)
|
Output:
Last Updated :
27 Jun, 2022
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...