Skip to content

Commit 8fe11fd

Browse files
[Term Entry] PyTorch Tensor Operations: .cosh()
* Create cosh.md * minor fixes * Update cosh.md ---------
1 parent a77e187 commit 8fe11fd

File tree

1 file changed

+55
-0
lines changed
  • content/pytorch/concepts/tensor-operations/terms/cosh

1 file changed

+55
-0
lines changed
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
---
2+
Title: '.cosh()'
3+
Description: 'Returns the hyperbolic cosine of the given input.'
4+
Subjects:
5+
- 'Computer Science'
6+
- 'Machine Learning'
7+
Tags:
8+
- 'Functions'
9+
- 'Machine Learning'
10+
- 'Python'
11+
- 'Tensor'
12+
CatalogContent:
13+
- 'intro-to-py-torch-and-neural-networks'
14+
- 'paths/computer-science'
15+
---
16+
17+
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.
18+
19+
## Syntax
20+
21+
```pseudo
22+
torch.cosh(input, *, out=None)
23+
```
24+
25+
**Parameters:**
26+
27+
- `input`: The input tensor containing elements for which to compute the hyperbolic cosine.
28+
- `out` (Optional): The output tensor to store the result. If provided, the result is written to this tensor in-place.
29+
30+
**Return value:**
31+
32+
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`.
33+
34+
## Example
35+
36+
This example demonstrates the usage of the `.cosh()` function:
37+
38+
```py
39+
import torch
40+
41+
# Input tensor
42+
a = torch.tensor([ 0.1632, 1.1835, -0.6979, -0.7325])
43+
44+
# Calculates hyperbolic cosine
45+
out = torch.cosh(a)
46+
47+
# Print the result
48+
print(out)
49+
```
50+
51+
Here is the output:
52+
53+
```shell
54+
tensor([ 1.0133, 1.7860, 1.2536, 1.2805])
55+
```

0 commit comments

Comments
 (0)