PyTorch .cosh()

Anonymous contributor's avatar
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.

  • 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

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 tensor
a = torch.tensor([ 0.1632, 1.1835, -0.6979, -0.7325])
# Calculates hyperbolic cosine
out = torch.cosh(a)
# Print the result
print(out)

Here is the output:

tensor([ 1.0133, 1.7860, 1.2536, 1.2805])

All contributors

Contribute to 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