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

Calculates an approximation to the tangent for each element \(x_i\) of the input tensor \(x\). Each element \(x_i\) is assumed to be expressed in radians.

This function has domain (-infinity, +infinity) and codomain (-infinity, +infinity).


x – input tensor whose elements are each expressed in radians. Should have a floating-point data type.


a tensor containing the tangent 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 +0.

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

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


>>> F.tan(0)
Tensor(0.0, device=xpux:0)

Element-wise tangent:

>>> import math
>>> x = Tensor([0, math.pi/4, math.pi])
>>> F.tan(x)
Tensor([0. 1. 0.], device=xpux:0)