megengine.functional.cos

cos(x)[源代码]

逐元素计算余弦函数。

实际案例

import numpy as np
from megengine import tensor
import megengine.functional as F

x = tensor(np.arange(0, 6, dtype=np.float32).reshape(2, 3))
out = F.cos(x)
print(out.numpy().round(decimals=4))

输出:

[[ 1.      0.5403 -0.4161]
 [-0.99   -0.6536  0.2837]]