# .cos()

Anonymous contributor
Anonymous contributor
Published Jun 20, 2024
Contribute to Docs

In NumPy, the `.cos()` function computes the cosine of each element in an array. This trigonometric function is essential for various mathematical computations, especially in physics, engineering, computer graphics, signal processing, and more.

## Syntax

``````numpy.cos(array, out = None, dtype = None)
``````
• `array`: The Python library that provides support for large, multi-dimensional arrays and matrices, along with a large collection of mathematical functions to operate on these arrays.
• `out`: Optional. This is an alternative output array in which to place the result. It must have the same shape as the expected output. If not provided, a new array is returned.
• `dtype`: Optional. The desired data type for the output array. If not provided, the data type of the input array is used.

## Example

The below example shows the `.cos()` function in use:

```import numpy as np
# A single angle in radiansangle = np.pi / 4
# Calculate the cosine of the anglecos_value = np.cos(angle)
```

The above code generates the output as below:

```Angle (radians): 0.7853981633974483Cosine value: 0.7071067811865476
```

## Codebyte Example

Run the following code to understand how the `.cos()` function works:

```import numpy as np
# Example array of angles in radiansangles = np.array([0, np.pi / 4, np.pi / 2, np.pi])
# Calculate the cosine of each anglecos_values = np.cos(angles)