

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to compute the inverse hyperbolic sine in PyTorch?
<p>The <strong>torch.asinh()</strong> method computes the inverse hyperbolic sine of each element of the input tensor. It supports both real and complex-valued inputs. It supports any dimension of the input tensor.</p><h3>Syntax</h3><pre class="just-code notranslate language-python" data-lang="python">torch.asinh(input)</pre><p>where <strong>input</strong> is the input tensor.</p><h3>Output</h3><p>It returns a tensor inverse hyperbolic sine of each element.</p><h3>Steps</h3><p>To compute the inverse hyperbolic sine of each element in the input tensor, you could follow the steps given below −</p><ul class="list"><li><p>Import the required library. In all the following examples, the required Python library is <strong>torch</strong>. Make sure you have already installed it.</p></li></ul><pre class="just-code notranslate language-python" data-lang="python">import torch</pre><ul class="list"><li><p>Create a torch tensor and print it.</p></li></ul><pre class="just-code notranslate language-python" data-lang="python">input = torch.randn(3,4) print("Input Tensor: ", input)</pre><ul class="list"><li><p>Compute the inverse hyperbolic sine of each element in the input tensor using <strong>torch.asinh(input)</strong>. Here input is the input tensor .</p></li></ul><pre class="just-code notranslate language-python" data-lang="python">inv_hsi = torch.asinh(input)</pre><ul class="list"><li><p>Display the computed tensor with inverse hyperbolic sine values.</p></li></ul><pre class="just-code notranslate language-python" data-lang="python">print("Inverse Hyperbolic Sine Tensor: ", inv_hsin)</pre><p>Now, let's take a couple of examples to demonstrate how to compute the inverse hyperbolic sine.</p><h2>Example 1</h2><pre class="just-code notranslate language-python" data-lang="python"># Import the required library import torch # define an input tensor input = torch.tensor([1.2, 3., 4., 4.2, -3.2]) # print the above defined tensor print("Input Tensor: ", input) # compute the inverse hyperbolic sine inv_hsin = torch.asinh(input) # print the above computed tensor print("Inverse Hyperbolic Sine Tensor: ", inv_hsin) print("............................") # define a complex input tensor input = torch.tensor([1.2+2j, 3.+4.j, 4.2-3.2j]) # print the above defined tensor print("Input Tensor: ", input) # compute the inverse hyperbolic sine inv_hsin = torch.asinh(input) # print the above computed tensor print("Inverse Hyperbolic Sine Tensor: ", inv_hsin)</pre><h2>Output</h2><pre class="result notranslate" style="">Input Tensor: tensor([ 1.2000, 3.0000, 4.0000, 4.2000, -3.2000]) Inverse Hyperbolic Sine Tensor: tensor([ 1.0160, 1.8184, 2.0947, 2.1421, -1.8799]) ............................ Input Tensor: tensor([1.2000+2.0000j, 3.0000+4.0000j, 4.2000-3.2000j]) Inverse Hyperbolic Sine Tensor: tensor([1.5205+0.9873j, 2.2999+0.9176j, 2.3596-0.6425j])</pre><p>In the above program, we computed the inverse hyperbolic sine of each element of the both real and complex-valued input tensors.</p><h2>Example 2</h2><pre class="just-code notranslate language-python" data-lang="python"># Import the required library import torch # define an input tensor input = torch.randn(4,4) # print the above defined tensor print("Input Tensor: ", input) # compute the inverse hyperbolic sine inv_hsin = torch.asinh(input) # print the above computed tensor print("Inverse Hyperbolic Sine Tensor: ", inv_hsin) print("............................") # define a complex input tensor real = torch.randn(2,3) imag = torch.randn(2,3) input = torch.complex(real, imag) # print the above defined tensor print("Input Tensor: ", input) # compute the inverse hyperbolic sine inv_hsin = torch.asinh(input) # print the above computed tensor print("Inverse Hyperbolic Sine Tensor: ", inv_hsin)</pre><h2>Output</h2><pre class="result notranslate">Input Tensor: tensor([[ 0.4057, -1.8063, -0.5133, 0.3540], [-0.7180, -1.0896, 0.1832, 1.9867], [-0.6352, -0.1913, -0.0541, -0.3637], [-0.6229, 0.5518, -0.8876, 2.8466]]) Inverse Hyperbolic Sine Tensor: tensor([[ 0.3953, -1.3535, -0.4931, 0.3470], [-0.6673, -0.9433, 0.1822, 1.4377], [-0.5988, -0.1901, -0.0541, -0.3561], [-0.5884, 0.5270, -0.7996, 1.7688]]) ............................ Input Tensor: tensor([[-0.7072+0.6690j, 0.2434-1.0732j, 1.2196-0.7483j], [-1.2849+0.1874j, -0.7717+1.3786j, 0.6163-0.0782j]]) Inverse Hyperbolic Sine Tensor: tensor([[-0.7525+0.5421j, 0.5764-1.1596j, 1.1148-0.4592j], [-1.0744+0.1149j, -1.1086+0.9624j, 0.5839-0.0666j]])</pre><p><strong>Note</strong> − In the above example, we have taken input tensors of randomly generated numbers. You may notice getting different elements.</p>
- Related Questions & Answers
- Compute the inverse Hyperbolic sine in Python
- How to compute the inverse cosine and inverse hyperbolic cosine in PyTorch?
- Compute the inverse Hyperbolic sine of array elements in Python
- Compute the Hyperbolic sine in Python
- Compute the inverse Hyperbolic cosine in Python
- Compute the inverse Hyperbolic tangent in Python
- Compute the inverse sine with scimath in Python
- Compute the Hyperbolic sine of the array elements in Python
- Compute the inverse hyperbolic tangent with scimath in Python
- Compute the inverse Hyperbolic tangent of array elements in Python
- Compute the inverse Hyperbolic cosine of array elements in Python
- How to compute the sine of elements of a tensor in PyTorch?
- PyTorch – How to compute the inverse of a square matrix?
- Compute the Hyperbolic tangent in Python
- Compute the Hyperbolic cosine in Python
Advertisements