megengine.functional.cos#

cos(x)[source]#

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].

Parameters:

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

Returns:

a tensor containing the cosine of each element in \(x\). The returned tensor must have a floating-point data type determined by Type promotion rules.

Examples

>>> 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)