---
title: cos
description: "计算每个元素的三角余弦值，即cos(x)。"
url: https://www.hikunpeng.com/document/detail/zh/kunpenghpcs/hpckit/devg/kunpengaccel_kml_1092.html
sourcePath: /source/zh/kunpenghpcs/hpckit/devg/kunpengaccel_kml_1092.html
indexId: c093dd805a35f8ee8c447aa0bdc7ec16e211837cf7417acd60388b50a8681fff61
---
# cos

#### 功能描述

计算每个元素的三角余弦值，即cos(x)。


#### 必选输入参数

| 参数名 | 类型 | 说明 |
| --- | --- | --- |
| x | array\_like | 输入的数组或标量，单位为弧度。 |


#### 可选输入参数

| 参数名 | 类型 | 默认值 | 说明 |
| --- | --- | --- | --- |
| out | ndarray或ndarray的元组 | None | 计算结果保存的位置。如果提供，其形状必须与输入数组广播后的形状一致。未指定时，返回一个新的数组。 |
| where | array\_like | None | 将被广播至输入的条件数组。在条件为真处的元素，其计算结果会存入out中，其余位置保留原有值。 |
| \*\*kwargs | \- | \- | 其他关键字参数，请参见NumPy官方文档Universal functions (ufunc)(https://numpy.org/doc/stable/reference/ufuncs.html\#ufuncs\-kwargs)。 |


#### 返回数据

| 类型 | 说明 |
| --- | --- |
| ndarray/scalar | 每个元素的三角余弦计算结果。 |


#### 示例

```
>>> import numpy as np
>>> np.cos(np.pi)
-1.0
>>> x = np.array([0., 30., 45., 60., 90.]) * np.pi / 180.0
>>> np.cos(x)
array([1.00000000e+00, 8.66025404e-01, 7.07106781e-01, 5.00000000e-01,
       6.12323400e-17])
>>>
```
