PyTorch .cosh()
Anonymous contributor
Published Aug 5, 2025
Contribute to Docs
In PyTorch, the .cosh() function computes the hyperbolic cosine of the input tensor. Hyperbolic functions like .cosh() are often used in signal processing, physics simulations, and certain neural network transformations.
Syntax
torch.cosh(input, *, out=None)
Parameters:
input: The input tensor containing elements for which to compute the hyperbolic cosine.out(Optional): The output tensor to store the result. If provided, the result is written to this tensor in-place.
Return value:
A tensor with the same shape as input, where each element is hyperbolic cosine of given element. If out is specified, the returned tensor is the same as out.
Example
This example demonstrates the usage of the .cosh() function:
import torch# Input tensora = torch.tensor([ 0.1632, 1.1835, -0.6979, -0.7325])# Calculates hyperbolic cosineout = torch.cosh(a)# Print the resultprint(out)
Here is the output:
tensor([ 1.0133, 1.7860, 1.2536, 1.2805])
All contributors
- Anonymous contributor
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
- Looking for an introduction to the theory behind programming? Master Python while learning data structures, algorithms, and more!
- Includes 6 Courses
- With Professional Certification
- Beginner Friendly.75 hours
- Learn how to use PyTorch to build, train, and test artificial neural networks in this course.
- Intermediate.3 hours