Skip to content

[Term Entry] PyTorch Tensor Operations: .cosh() #7357

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Aug 5, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 55 additions & 0 deletions content/pytorch/concepts/tensor-operations/terms/cosh/cosh.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
---
Title: '.cosh()'
Description: 'Returns the hyperbolic cosine of the given input.'
Subjects:
- 'Computer Science'
- 'Machine Learning'
Tags:
- 'Functions'
- 'Machine Learning'
- 'Python'
- 'Tensor'
CatalogContent:
- 'intro-to-py-torch-and-neural-networks'
- 'paths/computer-science'
---

In PyTorch, the **`.cosh()`** function computes the hyperbolic cosine of the input [tensor](https://www.codecademy.com/resources/docs/pytorch/tensors). Hyperbolic functions like `.cosh()` are often used in signal processing, physics simulations, and certain neural network transformations.

## Syntax

```pseudo
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:

```py
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:

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