.asin()
Published Mar 19, 2025
Contribute to Docs
The .asin()
method in PyTorch computes the inverse sine (arcsine) of each element in a tensor, returning the angle in radians whose sine is the input value. The input values must be in the range [-1, 1]
, and the output values lie within [-π/2, π/2]
. This method is useful in trigonometry, signal processing, and geometric transformations.
Syntax
torch.asin(input, *, out)
input
(Tensor): A tensor containing values in the range[-1, 1]
.out
(Tensor, optional): A tensor to store the output. If provided, it must have the same shape asinput
.
The .asin()
method returns a tensor where each element is the arcsine of the corresponding element in the input tensor.
Example
This example shows how to use the .asin()
method to compute the inverse sine of tensor elements:
import torch# Define a tensor with values in the range [-1, 1]tensor = torch.tensor([0.0, 0.5, -1.0, 1.0])# Compute inverse sine (arcsine)asin_tensor = torch.asin(tensor)print("Original Tensor:")print(tensor)print("\nArcsine Values:")print(asin_tensor)
This example results in the following output:
Original Tensor:tensor([ 0.0000, 0.5000, -1.0000, 1.0000])Arcsine Values:tensor([ 0.0000, 0.5236, -1.5708, 1.5708])
In this example, the output tensor shows the results of applying arcsin to each element:
asin(0.0) = 0.0
→ (sincesin(0) = 0
)asin(0.5) = π/6 ≈ 0.5236
→ (sincesin(π/6) = 0.5
)asin(-1.0) = -π/2 ≈ -1.5708
→ (sincesin(-π/2) = -1
)asin(1.0) = π/2 ≈ 1.5708
→ (sincesin(π/2) = 1
)
Additional Notes
- Valid Range: Input values outside
[-1, 1]
will result inNaN
(Not a number). - In-Place Operation: Use
.asin_()
to modify the tensor directly. - Complex Numbers: PyTorch’s
.asin()
supports complex tensors, computing the complex arcsine.
Contribute to Docs
- Learn more about how to get involved.
- Edit this page on GitHub to fix an error or make an improvement.
- Submit feedback to let us know how we can improve Docs.
Learn PyTorch on Codecademy
- Career path
Data Scientist: Machine Learning Specialist
Machine Learning Data Scientists solve problems at scale, make predictions, find patterns, and more! They use Python, SQL, and algorithms.Includes 27 CoursesWith Professional CertificationBeginner Friendly95 hours - Free course
Intro to PyTorch and Neural Networks
Learn how to use PyTorch to build, train, and test artificial neural networks in this course.Intermediate3 hours