# megengine.functional.cos¶

cos(x)[源代码]

Element-wise $$\cos(x)$$ function.

Calculates an approximation to the cosine 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 [-1, +1].

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

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

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


Element-wise cosine:

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