.acos()
Published Mar 16, 2025
Contribute to Docs
In PyTorch, the .acos()
function computes the inverse cosine (arccos) of each element in the input tensor. The result is given in radians and lies in the range [0, π]
. It is useful in trigonometric calculations and neural network applications where angles need to be determined from cosine values.
Syntax
torch.acos(input, *, out=None)
input
: The input tensor containing values in the range[-1, 1]
, since the arccosine function is only defined within this interval.out
(Optional): A tensor to store the output. If provided, it must have the same shape asinput
.
Example
The following example demonstrates the usage of the .acos()
function:
import torch# Define a tensorinput_tensor = torch.tensor([-1.0, -0.5, 0.0, 0.5, 1.0])# Compute the inverse cosine of each element in the input tensoroutput_tensor = torch.acos(input_tensor)# Print the resultant tensorprint(output_tensor)
The above code produces the following output:
tensor([3.1416, 2.0944, 1.5708, 1.0472, 0.0000])
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