Element-wise \(\cosh(x)\) function.

Calculates the hyperbolic cosine for each element \(x_i\) of the input tensor \(x\).

Equivalent to:

\[\frac {e^{x}+e^{-x}} {2}\]

This function has domain [-infinity, +infinity] and codomain [-infinity, +infinity].


x – input tensor whose elements each represent a hyperbolic angle. Should have a floating-point data type.


a tensor containing the hyperbolic cosine of each element in \(x\). The returned tensor must have a floating-point data type determined by 类型提升规则.

Special cases

For floating-point operands,

  • If \(x_i\) is NaN, the result is NaN.

  • If \(x_i\) is +0, the result is 1.

  • If \(x_i\) is -0, the result is 1.

  • If \(x_i\) is +infinity, the result is +infinity.

  • If \(x_i\) is -infinity, the result is +infinity.


>>> F.cosh(0)
Tensor(1.0, device=xpux:0)

Element-wise hyperbolic cosine:

>>> x = Tensor([0, 1, -1])
>>> F.cosh(x)
Tensor([1.     1.5431 1.5431], device=xpux:0)