mindspore.ops.cos

查看源文件
mindspore.ops.cos(input)[源代码]

逐元素计算输入的余弦。

\[out_i = \cos(x_i)\]

警告

如果使用float64,可能会存在精度丢失的问题。

参数:
  • input (Tensor) - Tensor的shape为 \((N,*)\) ,其中 \(*\) 表示任意数量的附加维度。

返回:

Tensor,shape与 input 相同。 当输入类型为bool、int8、uint8、int16、int32、int64时,返回值类型为float32。 否则,返回值类型与输入类型相同。

异常:
  • TypeError - 如果 input 不是Tensor。

  • TypeError -

    • CPU/GPU: 如果 input 的数据类型不是float16、float32、float64、complex64或complex128。

    • Ascend: 如果 input 的数据类型不是bool、int8、uint8、int16、int32、int64、float16、float32、float64、complex64或complex128。

支持平台:

Ascend GPU CPU

样例:

>>> import mindspore
>>> import numpy as np
>>> from mindspore import Tensor, ops
>>> input = Tensor(np.array([0.24, 0.83, 0.31, 0.09]), mindspore.float32)
>>> output = ops.cos(input)
>>> print(output)
[0.971338 0.6748758 0.95233357 0.9959527]